/* * 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 FFMPEG_KIT_CONFIG_H #define FFMPEG_KIT_CONFIG_H #include #include #include #include "FFmpegSession.h" #include "FFprobeSession.h" #include "Level.h" #include "LogCallback.h" #include "MediaInformationSession.h" #include "Signal.h" #include "StatisticsCallback.h" #include namespace ffmpegkit { /** *

Configuration class of FFmpegKit library. Allows customizing the global library * options. Provides helper methods to support additional resources. */ class FFmpegKitConfig { public: /** Global library version */ static constexpr const char* FFmpegKitVersion = "4.5.1"; /** * Prefix of named pipes created by ffmpeg-kit. */ static constexpr const char* FFmpegKitNamedPipePrefix = "fk_pipe_"; /** *

Enables log and statistics redirection. * *

When redirection is enabled FFmpeg/FFprobe logs are redirected to stdout and sessions * collect log and statistics entries for the executions. It is possible to define global or * session specific log/statistics callbacks as well. * *

Note that redirection is enabled by default. If you do not want to use its functionality * please use disableRedirection method to disable it. */ static void enableRedirection(); /** *

Disables log and statistics redirection. * *

When redirection is disabled logs are printed to stderr, all logs and statistics * callbacks are disabled and FFprobe's getMediaInformation methods * do not work. */ static void disableRedirection(); /** *

Sets and overrides fontconfig configuration directory. * * @param path directory that contains fontconfig configuration (fonts.conf) * @return zero on success, non-zero on error */ static int setFontconfigConfigurationPath(const char* path); /** *

Registers the fonts inside the given path, so they become available to use in FFmpeg * filters. * *

Note that you need to build FFmpegKit with fontconfig * enabled or use a prebuilt package with fontconfig inside to be able to use * fonts in FFmpeg. * * @param fontDirectoryPath directory that contains fonts (.ttf and .otf files) * @param fontNameMapping custom font name mappings, useful to access your fonts with more * friendly names */ static void setFontDirectory(const char* fontDirectoryPath, const std::map& fontNameMapping); /** *

Registers the fonts inside the given list of font directories, so they become available * to use in FFmpeg filters. * *

Note that you need to build FFmpegKit with fontconfig * enabled or use a prebuilt package with fontconfig inside to be able to use * fonts in FFmpeg. * * @param fontDirectoryList list of directories that contain fonts (.ttf and .otf files) * @param fontNameMapping custom font name mappings, useful to access your fonts with more * friendly names */ static void setFontDirectoryList(const std::list& fontDirectoryList, const std::map& fontNameMapping); /** *

Creates a new named pipe to use in FFmpeg operations. * *

Please note that creator is responsible of closing created pipes. * * @return the full path of the named pipe */ static std::shared_ptr registerNewFFmpegPipe(); /** *

Closes a previously created FFmpeg pipe. * * @param ffmpegPipePath full path of the FFmpeg pipe */ static void closeFFmpegPipe(const char* ffmpegPipePath); /** *

Returns the version of FFmpeg bundled within FFmpegKit library. * * @return the version of FFmpeg */ static std::string getFFmpegVersion(); /** * Returns FFmpegKit library version. * * @return FFmpegKit version */ static std::string getVersion(); /** *

Returns whether FFmpegKit release is a Long Term Release or not. * * @return true/yes or false/no */ static bool isLTSBuild(); /** * Returns FFmpegKit library build date. * * @return FFmpegKit library build date */ static std::string getBuildDate(); /** *

Sets an environment variable. * * @param variableName environment variable name * @param variableValue environment variable value * @return zero on success, non-zero on error */ static int setEnvironmentVariable(const char* variableName, const char* variableValue); /** *

Registers a new ignored signal. Ignored signals are not handled by FFmpegKit * library. * * @param signal signal to be ignored */ static void ignoreSignal(const ffmpegkit::Signal signal); /** *

Synchronously executes the FFmpeg session provided. * * @param ffmpegSession FFmpeg session which includes command options/arguments */ static void ffmpegExecute(const std::shared_ptr ffmpegSession); /** *

Synchronously executes the FFprobe session provided. * * @param ffprobeSession FFprobe session which includes command options/arguments */ static void ffprobeExecute(const std::shared_ptr ffprobeSession); /** *

Synchronously executes the media information session provided. * * @param mediaInformationSession media information session which includes command options/arguments * @param waitTimeout max time to wait until media information is transmitted */ static void getMediaInformationExecute(const std::shared_ptr mediaInformationSession, const int waitTimeout); /** *

Starts an asynchronous FFmpeg execution for the given session. * *

Note that this method returns immediately and does not wait the execution to complete. * You must use an FFmpegSessionCompleteCallback if you want to be notified about the result. * * @param ffmpegSession FFmpeg session which includes command options/arguments */ static void asyncFFmpegExecute(const std::shared_ptr ffmpegSession); /** *

Starts an asynchronous FFprobe execution for the given session. * *

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 ffprobeSession FFprobe session which includes command options/arguments */ static void asyncFFprobeExecute(const std::shared_ptr ffprobeSession); /** *

Starts an asynchronous FFprobe execution for the given media information session. * *

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 mediaInformationSession media information session which includes command options/arguments * @param waitTimeout max time to wait until media information is transmitted */ static void asyncGetMediaInformationExecute(const std::shared_ptr mediaInformationSession, int waitTimeout); /** *

Sets a global log callback to redirect FFmpeg/FFprobe logs. * * @param logCallback log callback or nil to disable a previously defined log callback */ static void enableLogCallback(const ffmpegkit::LogCallback logCallback); /** *

Sets a global statistics callback to redirect FFmpeg statistics. * * @param statisticsCallback statistics callback or nil to disable a previously defined statistics callback */ static void enableStatisticsCallback(const ffmpegkit::StatisticsCallback statisticsCallback); /** *

Sets a global FFmpegSessionCompleteCallback to receive execution results for FFmpeg sessions. * * @param ffmpegSessionCompleteCallback complete callback or nil to disable a previously defined callback */ static void enableFFmpegSessionCompleteCallback(const FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback); /** *

Returns the global FFmpegSessionCompleteCallback set. * * @return global FFmpegSessionCompleteCallback or nil if it is not set */ static FFmpegSessionCompleteCallback getFFmpegSessionCompleteCallback(); /** *

Sets a global FFprobeSessionCompleteCallback to receive execution results for FFprobe sessions. * * @param ffprobeSessionCompleteCallback complete callback or nil to disable a previously defined callback */ static void enableFFprobeSessionCompleteCallback(const FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback); /** *

Returns the global FFprobeSessionCompleteCallback set. * * @return global FFprobeSessionCompleteCallback or nil if it is not set */ static FFprobeSessionCompleteCallback getFFprobeSessionCompleteCallback(); /** *

Sets a global MediaInformationSessionCompleteCallback to receive execution results for MediaInformation sessions. * * @param mediaInformationSessionCompleteCallback complete callback or nil to disable a previously defined * callback */ static void enableMediaInformationSessionCompleteCallback(const MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback); /** *

Returns the global MediaInformationSessionCompleteCallback set. * * @return global MediaInformationSessionCompleteCallback or nil if it is not set */ static MediaInformationSessionCompleteCallback getMediaInformationSessionCompleteCallback(); /** * Returns the current log level. * * @return current log level */ static ffmpegkit::Level getLogLevel(); /** * Sets the log level. * * @param level new log level */ static void setLogLevel(const ffmpegkit::Level level); /** * Converts int log level to string. * * @param level value * @return string value */ static std::string logLevelToString(const ffmpegkit::Level level); /** * Returns the session history size. * * @return session history size */ static int getSessionHistorySize(); /** * Sets the session history size. * * @param sessionHistorySize session history size, should be smaller than 1000 */ static void setSessionHistorySize(const int sessionHistorySize); /** * Returns the session specified with sessionId from the session history. * * @param sessionId session identifier * @return session specified with sessionId or nil if it is not found in the history */ static std::shared_ptr getSession(const long sessionId); /** * Returns the last session created from the session history. * * @return the last session created or nil if session history is empty */ static std::shared_ptr getLastSession(); /** * Returns the last session completed from the session history. * * @return the last session completed. If there are no completed sessions in the history this * method will return nil */ static std::shared_ptr getLastCompletedSession(); /** *

Returns all sessions in the session history. * * @return all sessions in the session history */ static std::shared_ptr>> getSessions(); /** *

Clears all, including ongoing, sessions in the session history. *

Note that callbacks cannot be triggered for deleted sessions. */ static void clearSessions(); /** *

Returns all FFmpeg sessions in the session history. * * @return all FFmpeg sessions in the session history */ static std::shared_ptr>> getFFmpegSessions(); /** *

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

Returns all MediaInformation sessions in the session history. * * @return all MediaInformation sessions in the session history */ static std::shared_ptr>> getMediaInformationSessions(); /** *

Returns sessions that have the given state. * * @return sessions that have the given state from the session history */ static std::shared_ptr>> getSessionsByState(const SessionState state); /** * Returns the active log redirection strategy. * * @return log redirection strategy */ static LogRedirectionStrategy getLogRedirectionStrategy(); /** *

Sets the log redirection strategy * * @param logRedirectionStrategy log redirection strategy */ static void setLogRedirectionStrategy(const LogRedirectionStrategy logRedirectionStrategy); /** *

Returns the number of async messages that are not transmitted to the callbacks for * this session. * * @param sessionId id of the session * @return number of async messages that are not transmitted to the callbacks for this session */ static int messagesInTransmit(const long sessionId); /** * Converts session state to string. * * @param state session state * @return string value */ static std::string sessionStateToString(SessionState state); /** *

Parses the given command into arguments. Uses space character to split the arguments. * Supports single and double quote characters. * * @param command string command * @return list of arguments */ static std::shared_ptr> parseArguments(const char* command); /** *

Concatenates arguments into a string adding a space character between two arguments. * * @param arguments arguments * @return concatenated string containing all arguments */ static std::string argumentsToString(std::shared_ptr> arguments); }; } #endif // FFMPEG_KIT_CONFIG_H