FfmpegKit: Free and open-source extension for using FFmpeg

The FfmpegKit Extension is here to bring powerful media processing capabilities to your MIT App Inventor projects. Designed for ease of use and packed with advanced features, this free and open-source extension allows you to integrate FFmpeg into your apps effortlessly.

Whether you want to handle video compression, audio processing, media conversion, or work with advanced FFmpeg commands, this extension has you covered!

Latest Version: 1

Key Features

  • SAF Uri Conversion: Effortlessly read and write files using SAF paths.

    • GetSafParameterForRead: Convert SAF Uri into a readable path.
    • GetSafParameterForWrite: Convert SAF Uri into a writable path.
    • GetSafParameter: Flexible conversion with custom open modes.
  • Media Processing Commands:

    • Execute: Run FFmpeg commands synchronously.
    • ExecuteAsync: Execute commands asynchronously with progress monitoring.
  • Native Library Support:

    • LoadLibraries: Load native FFmpeg libraries from assets, files, or URLs.
  • FFmpeg Version Info: Access the FFmpeg version via the FFmpegVersion property.

  • Event Handlers for Asynchronous Execution:

    • GotNewLog: Captures logs during async execution.
    • GotNewStatistics: Provides live statistics for ongoing processes.
    • CommandSuccess, CommandFailed, and CommandCancelled for command status updates.
    • LibrariesLoaded: Confirms successful library loading.
  • Comprehensive Error Handling: Receive detailed error messages when issues occur.

Blocks

image

Documentation

Methods and Properties

Here’s a detailed list of available methods and properties:

Methods

  • GetSafParameterForRead(safUri: text): text – Convert SAF Uri to a readable path.

  • GetSafParameterForWrite(safUri: text): text – Convert SAF Uri to a writable path.

  • GetSafParameter(safUri: text, openMode: text): text – Convert SAF Uri for read/write.

  • LoadLibraries(zipPath: text) – Load native libraries from a zip file.

  • ExecuteMpeg(command: text) – Execute an FFmpeg command.

  • ExecuteMpegAsync(command: text) – Execute an FFmpeg command asynchronously.

  • ExecuteProbe(command: text) – Execute an FFprobe command.

  • ExecuteProbeAsync(command: text) – Execute an FFprobe command asynchronously.

Properties

  • FFmpegVersion (read-only) – Retrieve the current FFmpeg version.

Events

  • GotNewLog(sessionId: number, message: text) – Triggered on new log entry during async execution.

  • GotNewStatistics(sessionId: number, statistics: text) – Provides statistics during async execution.

  • CommandSuccess(async: boolean, isProbe: boolean, isMediaInformation: boolean, output: text) – Triggered on successful command execution.

  • CommandCancelled(async: boolean, output: text) – Triggered when a command is canceled.

  • CommandFailed(async: boolean, output: text) – Triggered on command failure.

  • ErrorOccurred(errorMsg: text) – Triggered when an error occurs.

  • LibrariesLoaded() – Triggered when native libraries are loaded successfully.

Usage Examples

First load native libraries from assets, file path or url.

Sample url: https://exp.sunnythedeveloper.in/ffmpeg.zip
(It doesn't contain binaries for all archs)

Only then you'll be able to use extension blocks.

Once libraries have been loaded, you can execute mpeg and probe commands synchronously as well as asynchronously.

Please refer to ffmpeg documentation to learn more about commands.

Source code and Aix

Download Aix:
com.sunny.ffmpeg.aix (110.0 KB)

This extension is open source! Explore the code or contribute at Github repo.

You will find aix there as well.

If you find this extension useful and want to support its development, consider donating. Your contributions help me continue creating free and open-source extensions.

PayPal: PayPal.Me
Buy me a coffee: https://buymeacoffee.com/vknow360
UPI: vknow360@apl

Important Notice :warning:

This extension uses FFmpegKit, which is distributed under its own license terms. It is the user's responsibility to ensure compliance with the FFmpegKit license when using this extension in their projects.

If you are using this extension in a private project, there is no need to worry about licensing. However, for public or commercial use, please review and adhere to the FFmpeg licensing terms and FFmpegKit licensing terms.

10 Likes

Brilliant! Game Changer!

Tested on video file in Download directory.

ffmpeg returned file info, just as it does on computer

ffmpeg re-encoded an mp4 video file to mkv and to webm without issue.

2 Likes

how to use it, any tutorials

See the usage examples, and the ffmpeg documentation linked above.

1 Like

Mainly you have to deal with various ffmpeg commands, so it would be better if you have prior knowledge about it. Otherwise you can refer to ffmpeg docs and various threads in online forums.

If you find any bug in extension then let me know.

1 Like

This is exactly what I was looking for today, excellent work.

3 Likes

This post was flagged by the community and is temporarily hidden.

@vknow360 How can we specify file address for retrieval and storage in command

Please help @TIMAI2

Do you mean the output file ?

Yes how can we mention where it should be stored also when editing a file how to specify its address. Will file picker uri work

If you read the ffmpeg documentation you will see how to construct a command. You can simply set the output file to be in the same directory as the input file, or provide a suitable path in the command.

For example:

-i input.mp4 -c copy output.mp4
(same directory)

-i input.mp4 -c copy /storage/emulated/0/Downloads/output.mp4
(not tested but assume this should work)

Given you have already provided the output file location, you do not need to get it back again...

1 Like

Already mentioned:

It is not like I do not want to help, but I also don't know much about ffmpeg commands.
You can use ChatGPT also.

Yes, but you will have to parse uri with either of the blocks related to SAF.

1 Like

Thanks @TIMAI2 @vknow360
How to Post file with these fields also using web comp
curl "https://api.groq.com/openai/v1/audio/transcriptions"
-F "model=whisper-large-v3-turbo"
-F "file=@./audio.m4a"
-F "response_format=verbose_json"
-X POST

as only path is there

Some context would help.

What exactly are you trying to achieve ? Looks like a multipart url/upload so not possible to use the web component for that.
What does this have to do with the extension ?
Files will need to be on the device where you are executing the commands for ffmpeg.

This looks like some kind of AI API. And it probably has nothing to do with ffmpeg.