/* * Copyright (c) 2022 Taner Sener * * This file is part of FFmpegKit. * * FFmpegKit is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * FFmpegKit is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with FFmpegKit. If not, see . */ #ifndef FFPROBE_KIT_H #define FFPROBE_KIT_H #include #include #include "FFprobeSession.h" #include "MediaInformationJsonParser.h" #include "MediaInformationSession.h" namespace ffmpegkit { /** *

Main class to run FFprobe commands. Supports executing commands both synchronously and * asynchronously. *

     * auto session = FFprobeKit::execute("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4");
     *
     * auto asyncSession = FFprobeKit::executeAsync("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4", [](auto session){ ... });
     * 
*

Provides overloaded execute methods to define session specific callbacks. *

     * auto session = FFprobeKit::executeAsync("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4", [](auto session){ ... }, [](auto log){ ... }];
     * 
*

It can extract media information for a file or a url, using getMediaInformation method. *

     * auto session = FFprobeKit::getMediaInformation("file1.mp4");
     * 
*/ class FFprobeKit { public: /** *

Synchronously executes FFprobe with arguments provided. * * @param arguments FFprobe command options/arguments as string array * @return FFprobe session created for this execution */ static std::shared_ptr executeWithArguments(const std::list& arguments); /** *

Starts an asynchronous FFprobe execution with arguments provided. * *

Note that this method returns immediately and does not wait the execution to complete. * You must use an FFprobeSessionCompleteCallback if you want to be notified about the result. * * @param arguments FFprobe command options/arguments as string array * @param completeCallback callback that will be called when the execution has completed * @return FFprobe session created for this execution */ static std::shared_ptr executeWithArgumentsAsync(const std::list& arguments, FFprobeSessionCompleteCallback completeCallback); /** *

Starts an asynchronous FFprobe execution with arguments provided. * *

Note that this method returns immediately and does not wait the execution to complete. * You must use an FFprobeSessionCompleteCallback if you want to be notified about the result. * * @param arguments FFprobe command options/arguments as string array * @param completeCallback callback that will be notified when execution has completed * @param logCallback callback that will receive logs * @return FFprobe session created for this execution */ static std::shared_ptr executeWithArgumentsAsync(const std::list& arguments, FFprobeSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback); /** *

Synchronously executes FFprobe command provided. Space character is used to split command * into arguments. You can use single or double quote characters to specify arguments inside * your command. * * @param command FFprobe command * @return FFprobe session created for this execution */ static std::shared_ptr execute(const std::string command); /** *

Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command * into arguments. You can use single or double quote characters to specify arguments inside your command. * *

Note that this method returns immediately and does not wait the execution to complete. You must use an * FFprobeSessionCompleteCallback if you want to be notified about the result. * * @param command FFprobe command * @param completeCallback callback that will be called when the execution has completed * @return FFprobe session created for this execution */ static std::shared_ptr executeAsync(const std::string command, FFprobeSessionCompleteCallback completeCallback); /** *

Starts an asynchronous FFprobe execution for the given command. Space character is used to split the command * into arguments. You can use single or double quote characters to specify arguments inside your command. * *

Note that this method returns immediately and does not wait the execution to complete. You must use an * FFprobeSessionCompleteCallback if you want to be notified about the result. * * @param command FFprobe command * @param completeCallback callback that will be notified when execution has completed * @param logCallback callback that will receive logs * @return FFprobe session created for this execution */ static std::shared_ptr executeAsync(const std::string command, FFprobeSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback); /** *

Extracts media information for the file specified with path. * * @param path path or uri of a media file * @return media information session created for this execution */ static std::shared_ptr getMediaInformation(const std::string path); /** *

Extracts media information for the file specified with path. * * @param path path or uri of a media file * @param waitTimeout max time to wait until media information is transmitted * @return media information session created for this execution */ static std::shared_ptr getMediaInformation(const std::string path, const int waitTimeout); /** *

Starts an asynchronous FFprobe execution to extract the media information for the specified file. * *

Note that this method returns immediately and does not wait the execution to complete. You must use an * MediaInformationSessionCompleteCallback if you want to be notified about the result. * * @param path path or uri of a media file * @param completeCallback callback that will be called when the execution has completed * @return media information session created for this execution */ static std::shared_ptr getMediaInformationAsync(const std::string path, MediaInformationSessionCompleteCallback completeCallback); /** *

Starts an asynchronous FFprobe execution to extract the media information for the specified file. * *

Note that this method returns immediately and does not wait the execution to complete. You must use an * MediaInformationSessionCompleteCallback if you want to be notified about the result. * * @param path path or uri of a media file * @param completeCallback callback that will be notified when execution has completed * @param logCallback callback that will receive logs * @param waitTimeout max time to wait until media information is transmitted * @return media information session created for this execution */ static std::shared_ptr getMediaInformationAsync(const std::string path, MediaInformationSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback, const int waitTimeout); /** *

Extracts media information using the command provided asynchronously. * * @param command FFprobe command that prints media information for a file in JSON format * @return media information session created for this execution */ static std::shared_ptr getMediaInformationFromCommand(const std::string command); /** *

Lists all FFprobe sessions in the session history. * * @return all FFprobe sessions in the session history */ static std::shared_ptr>> listFFprobeSessions(); /** *

Lists all MediaInformation sessions in the session history. * * @return all MediaInformation sessions in the session history */ static std::shared_ptr>> listMediaInformationSessions(); }; } #endif // FFPROBE_KIT_H