B4A Library PndFFmpegKit - FFmpeg Library

FFmpegKit is a wrapper library that allows you to easily run FFmpeg/FFprobe commands in applications. It provides additional features on top of FFmpeg to enable platform specific resources, control how commands are executed and how the results are handled.
Original library: https://github.com/arthenica/ffmpeg-kit

Wrapper is based on v5.1.0 LTS version, supports Android API 16+
Supported Android architectures: arm-v7a, arm-v7a-neon, arm64-v8a, x86, x86-64.
You can use whatever command from FFmpeg, example app is just example how to use this lib/wrapper.
If you find FFmpeg command with quotes " replace quotes " to single quote ', like in variable FFmpegCommand in Video to Gif example.

Useful documentation and commands:

PndFFmpegKit

Author:
Author: Taner Şener - B4a Wrapper: Pendrush
Version: 5.10
  • PndFFmpegKit
    • Events:
      • Log (FFmpegLog As PndFFmpegLog)
      • MediaInfoSessionComplete (Session As PndFFmpegSession)
      • ProbeSessionComplete (Session As PndFFmpegSession)
      • SessionComplete (Session As PndFFmpegSession)
      • Statistics (Stats As PndFFmpegStatistics)
    • Functions:
      • CancelAll
        Cancels all running sessions.
        This method does not wait for termination to complete and returns immediately.
      • CancelSession (SessionId As Long)
        Cancels the session specified with sessionId.
        This method does not wait for termination to complete and returns immediately
      • ClearSessions
        Clears all, including ongoing, sessions in the session history.
        Note that callbacks cannot be triggered for deleted sessions
      • ExecuteAsync (Command As String) As PndFFmpegSession
        Starts an asynchronous FFmpeg 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.
      • ExecuteWithArgumentsAsync (Command As String()) As PndFFmpegSession
        Starts an asynchronous FFmpeg execution with arguments provided.
        Note that this method returns immediately and does not wait the execution to complete.
      • GetMediaInformationAsync (Path As String)
        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.
      • Initialize (EventName As String)
        Initialize FFMpegKit
        FFmpegKit.Initialize("FFmpegKit")
        Dim InputFilePath As String = File.Combine(File.DirInternal, "1.mp4")
        Dim OutputFilePath As String = File.Combine(File.DirInternal, "2.mp4")
        Dim FFmpegCommand As String = "-i " & InputFilePath & " -c:v mpeg4 " & OutputFilePath
        FFmpegKit.ExecuteAsync(FFmpegCommand)
      • ListMediaInformationSessions As List
        Lists all MediaInformation sessions in the session history.
      • ListProbeSessions As List
        Lists all FFprobe sessions in the session history.
      • ListSessions As List
        Lists all FFmpeg sessions in the session history.
      • ProbeExecuteAsync (Command As String) As PndFFmpegSession
        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.
      • SetFontconfigConfigurationPath (Path As String) As Int
        Sets and overrides fontconfig configuration directory.
        Directory that contains fontconfig configuration (fonts.conf)
        Return zero on success, non-zero on error.
      • UpdateSession (SessionId As Long) As PndFFmpegSession
        Get update for SessionId.
    • Properties:
      • Abi As String [read only]
        Returns the ABI name loaded
      • AsyncConcurrencyLimit
        Returns the maximum number of async sessions that will be executed in parallel.
      • CpuAbi As String [read only]
        Returns the ABI name of the cpu running
      • LogLevel As com.arthenica.ffmpegkit.Level [write only]
        Sets the log level
      • SessionHistorySize
        Returns the session history size.
  • PndFFmpegLog
    • Properties:
      • Message As String [read only]
        Returns log message.
      • SessionId As Long [read only]
        Returns the session identifier.
  • PndFFmpegLogLevel
    • Fields:
      • LOG_LEVEL_DEBUG As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_ERROR As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_FATAL As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_INFO As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_PANIC As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_QUIET As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_STDERR As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_TRACE As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_VERBOSE As com.arthenica.ffmpegkit.Level
      • LOG_LEVEL_WARNING As com.arthenica.ffmpegkit.Level
  • PndFFmpegReturnCode
    • Fields:
      • VALUE_CANCEL As Int
      • VALUE_SUCCESS As Int
    • Functions:
      • IsValueCancel As Boolean
      • IsValueError As Boolean
      • IsValueSuccess As Boolean
    • Properties:
      • IsCancel As Boolean [read only]
      • IsSuccess As Boolean [read only]
      • Value As Int [read only]
  • PndFFmpegSession
    • Properties:
      • Command As String [read only]
        Returns command arguments as a concatenated string
      • CreateTime As java.util.Date [read only]
        Returns session create time.
      • Duration As Long [read only]
        Time taken to execute this session in milliseconds or zero (0) if the session is not over yet
      • EndTime As java.util.Date [read only]
        Returns session end time.
      • Output As String [read only]
        Returns the log output generated while running the session.
      • ReturnCode As PndFFmpegReturnCode [read only]
        Returns the return code for this session. Note that return code is only set for sessions that end with COMPLETED state. If a session is not started, still running or failed then this method returns null.
      • SessionId As Long [read only]
        Returns the session identifier.
      • SessionState As String [read only]
        Returns the state of the session.
        Possible values:
        CREATED
        RUNNING
        FAILED
        COMPLETED
  • PndFFmpegStatistics
    • Properties:
      • Bitrate As Double [read only]
        Returns bitrate
      • SessionId As Long [read only]
        Returns the session identifier.
      • Size As Long [read only]
        Returns file size.
      • Speed As Double [read only]
        Returns speed
      • Time As Int [read only]
        Returns curent video time.
      • VideoFps As Float [read only]
        Returns video FPS.
      • VideoFrameNumber As Int [read only]
        Returns video frame number.
      • VideoQuality As Float [read only]
        Returns video quality.

Screenshot_1641716305_1.jpg Screenshot_1641716326_1.jpg Screenshot_1641716358_1.jpg Screenshot_1641716378_1.jpg Screenshot_1641813751_1.jpg

Example app: https://www.dropbox.com/s/z8z0iq9majtaill/FFmpegKitExample.zip?dl=0
Additional download: https://github.com/arthenica/ffmpeg-kit/releases/download/v5.1.LTS/ffmpeg-kit-full-gpl-5.1.LTS.aar
Put file from additional download in Additional library folder together with files from FFmpegKitLibrary.zip
 

Attachments

  • FFmpegKitLibrary.zip
    29.3 KB · Views: 200
Last edited:

asales

Expert
Licensed User
Longtime User
Great work. Thanks!

I saw that the ffmpeg-kit has several packages:

Can I use only the min package or the video package to decrease the final size of the app?

Thanks for your support.
 

asales

Expert
Licensed User
Longtime User
Is there a way to use the filter with (') in ExecuteAsync instead ExecuteWithArgumentsAsync?
(quote: because of this part :force_style='fontsize=70,PrimaryColour=&H00FF99AA' we need to use ExecuteWithArgumentsAsync as ExecuteAsync will remove ' from command)

I try to merge drawtext with subtitles. It works with ExecuteAsync, but I can't use the force_style.
B4X:
FFmpegCommand = "-i " & InputFilePath & " -vf 'drawtext=fontsize=40:text=" & TextOverVideo & ":y=85','subtitles=" & InputSubtitlesPath & "' -acodec copy -y " & OutputFilePath

If I use the same command in ExecuteWithArgumentsAsync, don't works.
B4X:
Dim FFmpegCommandArray() As String = Array As String("-i", InputFilePath, "-vf", "drawtext=fontfile=" & InputFontPath & ":text=" & TextOverVideo & ":fontsize=50:fontcolor=white", "subtitles=" & InputSubtitlesPath, "-acodec", "copy", "-y", OutputFilePath)

Any help are welcome. Thanks.
 

Pendrush

Well-Known Member
Licensed User
Longtime User
This code work:
B4X:
Dim FFmpegCommandArray() As String = Array As String("-i", InputFilePath, "-vf", "drawtext=fontfile=" & InputFontPath & ":text=" & TextOverVideo & ":fontsize=50:fontcolor=white:x=50:y=100", "-acodec", "copy", "-y", OutputFilePath)
 

asales

Expert
Licensed User
Longtime User
Thanks.
I found the problem. I was using the separator to drawtext and subtitle filters in FFmpegCommandArray and this is the problem.
Here is the correct code:
B4X:
Dim FFmpegCommandArray() As String = Array As String("-i", InputFilePath, "-vf", "drawtext=fontfile=" & InputFontPath & ":text=" & TextOverVideo  & ":fontsize=50:fontcolor=white:x=(w-text_w)/2:y=100" & ", subtitles=" & InputSubtitlesPath & ":force_style='fontsize=30,PrimaryColour=&H00FFFFFF,OutlineColour=&HFF000000,Bold=1,Alignment=10'", "-acodec", "copy", "-y", OutputFilePath)
 
Top