How to Use FFmpeg in Android
FFmpeg is an open-source project full of useful libraries for processing video/audio. You can change a file format, adjust quality through compression, extract audio, create GIFs, and more.
Why did I need this? I needed to build a feature that allows a user to create a video from a series of photos for my Collage app.
Step 1
Taner Sener has created a great ffmpeg-kit library that wraps the core ffmpeg code in various wrappers for use in iOS, Android, Flutter, etc.
implementation 'com.arthenica:ffmpeg-kit-full:4.5.1-1'
- There are other packages. If you want the libx264 encoder, for example, you will want to instead go for the full-gpl package:
implementation 'com.arthenica:ffmpeg-kit-full-gpl:4.5.1-1'
- There’s no need to build the binary yourself.
Step 2
Read the documentation on the README for the ffmpeg-kit project. It’s a great overview for various topics:
- Execute sync commands
- FFmpegSession for each sync/async call
- Execute async commands
- Get media information for a file
- Stop ongoing FFmpeg operations
Step 3
Understand ffmpeg commands in more detail. If this is your first time you will want to read up on documentation or visit stackoverflow posts.
Useful links for getting started:
- Complete list of arguments that’s outputted by running
ffmpeg -h full
- ffmpeg Documentation
- Converting video files to different formats
- Convert Images to a Video Sequence
Step 4
Build something cool!
- Give this post a clap or leave a comment.
- If there’s enough interest, I’ll follow up with exactly how I built my feature for taking a list of image links, downloading them in separate threads, then using FFmpeg to combine them into a video slideshow.