Class FFmpegKitConfig


  • public class FFmpegKitConfig
    extends java.lang.Object

    Configuration class of FFmpegKit library.

    • Method Detail

      • enableRedirection

        public static void enableRedirection()

        Enables log and statistics redirection.

        When redirection is enabled FFmpeg/FFprobe logs are redirected to Logcat 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() to disable it.

      • disableRedirection

        public static void disableRedirection()

        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.

      • setFontconfigConfigurationPath

        public static int setFontconfigConfigurationPath​(java.lang.String path)

        Sets and overrides fontconfig configuration directory.

        Parameters:
        path - directory that contains fontconfig configuration (fonts.conf)
        Returns:
        zero on success, non-zero on error
      • setFontDirectory

        public static void setFontDirectory​(android.content.Context context,
                                            java.lang.String fontDirectoryPath,
                                            java.util.Map<java.lang.String,​java.lang.String> fontNameMapping)

        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.

        Parameters:
        context - application context to access application data
        fontDirectoryPath - directory that contains fonts (.ttf and .otf files)
        fontNameMapping - custom font name mappings, useful to access your fonts with more friendly names
      • setFontDirectoryList

        public static void setFontDirectoryList​(android.content.Context context,
                                                java.util.List<java.lang.String> fontDirectoryList,
                                                java.util.Map<java.lang.String,​java.lang.String> 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.

        Parameters:
        context - application context to access application data
        fontDirectoryList - list of directories that contain fonts (.ttf and .otf files)
        fontNameMapping - custom font name mappings, useful to access your fonts with more friendly names
      • registerNewFFmpegPipe

        public static java.lang.String registerNewFFmpegPipe​(android.content.Context context)

        Creates a new named pipe to use in FFmpeg operations.

        Please note that creator is responsible of closing created pipes.

        Parameters:
        context - application context
        Returns:
        the full path of the named pipe
      • closeFFmpegPipe

        public static void closeFFmpegPipe​(java.lang.String ffmpegPipePath)

        Closes a previously created FFmpeg pipe.

        Parameters:
        ffmpegPipePath - full path of the FFmpeg pipe
      • getSupportedCameraIds

        public static java.util.List<java.lang.String> getSupportedCameraIds​(android.content.Context context)
        Returns the list of camera ids supported. These devices can be used in FFmpeg commands.

        Note that this method requires API Level ≥ 24. On older API levels it returns an empty list.

        Parameters:
        context - application context
        Returns:
        list of camera ids supported or an empty list if no supported cameras are found
      • getFFmpegVersion

        public static java.lang.String getFFmpegVersion()

        Returns the version of FFmpeg bundled within FFmpegKit library.

        Returns:
        the version of FFmpeg
      • getVersion

        public static java.lang.String getVersion()

        Returns FFmpegKit library version.

        Returns:
        FFmpegKit version
      • isLTSBuild

        public static boolean isLTSBuild()

        Returns whether FFmpegKit release is a Long Term Release or not.

        Returns:
        true/yes or false/no
      • getBuildDate

        public static java.lang.String getBuildDate()

        Returns FFmpegKit library build date.

        Returns:
        FFmpegKit library build date
      • printToLogcat

        public static void printToLogcat​(int logPriority,
                                         java.lang.String string)

        Prints the given string to Logcat using the given priority. If string provided is bigger than the Logcat buffer, the string is printed in multiple lines.

        Parameters:
        logPriority - one of Log.VERBOSE, Log.DEBUG, Log.INFO, Log.WARN, Log.ERROR, Log.ASSERT
        string - string to be printed
      • setEnvironmentVariable

        public static int setEnvironmentVariable​(java.lang.String variableName,
                                                 java.lang.String variableValue)

        Sets an environment variable.

        Parameters:
        variableName - environment variable name
        variableValue - environment variable value
        Returns:
        zero on success, non-zero on error
      • ignoreSignal

        public static void ignoreSignal​(Signal signal)

        Registers a new ignored signal. Ignored signals are not handled by FFmpegKit library.

        Parameters:
        signal - signal to be ignored
      • ffmpegExecute

        public static void ffmpegExecute​(FFmpegSession ffmpegSession)

        Synchronously executes the FFmpeg session provided.

        Parameters:
        ffmpegSession - FFmpeg session which includes command options/arguments
      • ffprobeExecute

        public static void ffprobeExecute​(FFprobeSession ffprobeSession)

        Synchronously executes the FFprobe session provided.

        Parameters:
        ffprobeSession - FFprobe session which includes command options/arguments
      • getMediaInformationExecute

        public static void getMediaInformationExecute​(MediaInformationSession mediaInformationSession,
                                                      int waitTimeout)

        Synchronously executes the media information session provided.

        Parameters:
        mediaInformationSession - media information session which includes command options/arguments
        waitTimeout - max time to wait until media information is transmitted
      • asyncFFmpegExecute

        public static void asyncFFmpegExecute​(FFmpegSession ffmpegSession)

        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.

        Parameters:
        ffmpegSession - FFmpeg session which includes command options/arguments
      • asyncFFmpegExecute

        public static void asyncFFmpegExecute​(FFmpegSession ffmpegSession,
                                              java.util.concurrent.ExecutorService executorService)

        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.

        Parameters:
        ffmpegSession - FFmpeg session which includes command options/arguments
        executorService - executor service that will be used to run this asynchronous operation
      • asyncFFprobeExecute

        public static void asyncFFprobeExecute​(FFprobeSession ffprobeSession)

        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.

        Parameters:
        ffprobeSession - FFprobe session which includes command options/arguments
      • asyncFFprobeExecute

        public static void asyncFFprobeExecute​(FFprobeSession ffprobeSession,
                                               java.util.concurrent.ExecutorService executorService)

        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.

        Parameters:
        ffprobeSession - FFprobe session which includes command options/arguments
        executorService - executor service that will be used to run this asynchronous operation
      • asyncGetMediaInformationExecute

        public static void asyncGetMediaInformationExecute​(MediaInformationSession mediaInformationSession,
                                                           int waitTimeout)

        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 a MediaInformationSessionCompleteCallback if you want to be notified about the result.

        Parameters:
        mediaInformationSession - media information session which includes command options/arguments
        waitTimeout - max time to wait until media information is transmitted
      • asyncGetMediaInformationExecute

        public static void asyncGetMediaInformationExecute​(MediaInformationSession mediaInformationSession,
                                                           java.util.concurrent.ExecutorService executorService,
                                                           int waitTimeout)

        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 a MediaInformationSessionCompleteCallback if you want to be notified about the result.

        Parameters:
        mediaInformationSession - media information session which includes command options/arguments
        executorService - executor service that will be used to run this asynchronous operation
        waitTimeout - max time to wait until media information is transmitted
      • getAsyncConcurrencyLimit

        public static int getAsyncConcurrencyLimit()
        Returns the maximum number of async sessions that will be executed in parallel.
        Returns:
        maximum number of async sessions that will be executed in parallel
      • setAsyncConcurrencyLimit

        public static void setAsyncConcurrencyLimit​(int asyncConcurrencyLimit)
        Sets the maximum number of async sessions that will be executed in parallel. If more sessions are submitted those will be queued.
        Parameters:
        asyncConcurrencyLimit - new async concurrency limit
      • enableLogCallback

        public static void enableLogCallback​(LogCallback logCallback)

        Sets a global callback to redirect FFmpeg/FFprobe logs.

        Parameters:
        logCallback - log callback or null to disable a previously defined callback
      • enableStatisticsCallback

        public static void enableStatisticsCallback​(StatisticsCallback statisticsCallback)

        Sets a global callback to redirect FFmpeg statistics.

        Parameters:
        statisticsCallback - statistics callback or null to disable a previously defined callback
      • enableFFmpegSessionCompleteCallback

        public static void enableFFmpegSessionCompleteCallback​(FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback)

        Sets a global FFmpegSessionCompleteCallback to receive execution results for FFmpeg sessions.

        Parameters:
        ffmpegSessionCompleteCallback - complete callback or null to disable a previously defined callback
      • getFFmpegSessionCompleteCallback

        public static FFmpegSessionCompleteCallback getFFmpegSessionCompleteCallback()

        Returns the global FFmpegSessionCompleteCallback set.

        Returns:
        global FFmpegSessionCompleteCallback or null if it is not set
      • enableFFprobeSessionCompleteCallback

        public static void enableFFprobeSessionCompleteCallback​(FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback)

        Sets a global FFprobeSessionCompleteCallback to receive execution results for FFprobe sessions.

        Parameters:
        ffprobeSessionCompleteCallback - complete callback or null to disable a previously defined callback
      • getFFprobeSessionCompleteCallback

        public static FFprobeSessionCompleteCallback getFFprobeSessionCompleteCallback()

        Returns the global FFprobeSessionCompleteCallback set.

        Returns:
        global FFprobeSessionCompleteCallback or null if it is not set
      • enableMediaInformationSessionCompleteCallback

        public static void enableMediaInformationSessionCompleteCallback​(MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback)

        Sets a global MediaInformationSessionCompleteCallback to receive execution results for MediaInformation sessions.

        Parameters:
        mediaInformationSessionCompleteCallback - complete callback or null to disable a previously defined callback
      • getMediaInformationSessionCompleteCallback

        public static MediaInformationSessionCompleteCallback getMediaInformationSessionCompleteCallback()

        Returns the global MediaInformationSessionCompleteCallback set.

        Returns:
        global MediaInformationSessionCompleteCallback or null if it is not set
      • getLogLevel

        public static Level getLogLevel()
        Returns the current log level.
        Returns:
        current log level
      • setLogLevel

        public static void setLogLevel​(Level level)
        Sets the log level.
        Parameters:
        level - new log level
      • getSafParameter

        public static java.lang.String getSafParameter​(android.content.Context context,
                                                       android.net.Uri uri,
                                                       java.lang.String openMode)

        Converts the given Structured Access Framework Uri ("content:…") into an SAF protocol url that can be used in FFmpeg and FFprobe commands.

        Requires API Level 19+. On older API levels it returns an empty url.

        Parameters:
        context - application context
        uri - SAF uri
        openMode - file mode to use as defined in ContentProvider.openFile
        Returns:
        input/output url that can be passed to FFmpegKit or FFprobeKit
      • getSafParameterForRead

        public static java.lang.String getSafParameterForRead​(android.content.Context context,
                                                              android.net.Uri uri)

        Converts the given Structured Access Framework Uri ("content:…") into an SAF protocol url that can be used in FFmpeg and FFprobe commands.

        Requires API Level ≥ 19. On older API levels it returns an empty url.

        Parameters:
        context - application context
        uri - SAF uri
        Returns:
        input url that can be passed to FFmpegKit or FFprobeKit
      • getSafParameterForWrite

        public static java.lang.String getSafParameterForWrite​(android.content.Context context,
                                                               android.net.Uri uri)

        Converts the given Structured Access Framework Uri ("content:…") into an SAF protocol url that can be used in FFmpeg and FFprobe commands.

        Requires API Level ≥ 19. On older API levels it returns an empty url.

        Parameters:
        context - application context
        uri - SAF uri
        Returns:
        output url that can be passed to FFmpegKit or FFprobeKit
      • getSessionHistorySize

        public static int getSessionHistorySize()
        Returns the session history size.
        Returns:
        session history size
      • setSessionHistorySize

        public static void setSessionHistorySize​(int sessionHistorySize)
        Sets the session history size.
        Parameters:
        sessionHistorySize - session history size, should be smaller than 1000
      • getSession

        public static Session getSession​(long sessionId)
        Returns the session specified with sessionId from the session history.
        Parameters:
        sessionId - session identifier
        Returns:
        session specified with sessionId or null if it is not found in the history
      • getLastSession

        public static Session getLastSession()
        Returns the last session created from the session history.
        Returns:
        the last session created or null if session history is empty
      • getLastCompletedSession

        public static Session getLastCompletedSession()
        Returns the last session completed from the session history.
        Returns:
        the last session completed. If there are no completed sessions in the history this method will return null
      • getSessions

        public static java.util.List<Session> getSessions()

        Returns all sessions in the session history.

        Returns:
        all sessions in the session history
      • clearSessions

        public static void clearSessions()

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

        Note that callbacks cannot be triggered for deleted sessions.

      • getFFmpegSessions

        public static java.util.List<FFmpegSession> getFFmpegSessions()

        Returns all FFmpeg sessions in the session history.

        Returns:
        all FFmpeg sessions in the session history
      • getFFprobeSessions

        public static java.util.List<FFprobeSession> getFFprobeSessions()

        Returns all FFprobe sessions in the session history.

        Returns:
        all FFprobe sessions in the session history
      • getMediaInformationSessions

        public static java.util.List<MediaInformationSession> getMediaInformationSessions()

        Returns all MediaInformation sessions in the session history.

        Returns:
        all MediaInformation sessions in the session history
      • getSessionsByState

        public static java.util.List<Session> getSessionsByState​(SessionState state)

        Returns sessions that have the given state.

        Parameters:
        state - session state
        Returns:
        sessions that have the given state from the session history
      • getLogRedirectionStrategy

        public static LogRedirectionStrategy getLogRedirectionStrategy()
        Returns the active log redirection strategy.
        Returns:
        log redirection strategy
      • setLogRedirectionStrategy

        public static void setLogRedirectionStrategy​(LogRedirectionStrategy logRedirectionStrategy)

        Sets the log redirection strategy

        Parameters:
        logRedirectionStrategy - log redirection strategy
      • sessionStateToString

        public static java.lang.String sessionStateToString​(SessionState state)
        Converts session state to string.
        Parameters:
        state - session state
        Returns:
        string value
      • parseArguments

        public static java.lang.String[] parseArguments​(java.lang.String command)

        Parses the given command into arguments. Uses space character to split the arguments. Supports single and double quote characters.

        Parameters:
        command - string command
        Returns:
        array of arguments
      • argumentsToString

        public static java.lang.String argumentsToString​(java.lang.String[] arguments)

        Concatenates arguments into a string adding a space character between two arguments.

        Parameters:
        arguments - arguments
        Returns:
        concatenated string containing all arguments
      • messagesInTransmit

        public static int messagesInTransmit​(long sessionId)

        Returns the number of native messages that are not transmitted to the Java callbacks for this session natively.

        Parameters:
        sessionId - id of the session
        Returns:
        number of native messages that are not transmitted to the Java callbacks for this session natively