FFmpeg meets Flutter 🀝

Abdul Rehman
3 min readSep 25, 2022

--

In this article, we will see how to add FFmpeg to our Flutter app and implement creative functionalities 🎨

πŸ›  FFmpeg is a tool used to process video and audio files. It is widely used for format transcoding πŸ”„, basic editing (trimming and concatenation) πŸŽ₯, video scaling, video post-production effects πŸ“Έ.

Let’s add FFmpeg to our project πŸ“²

There are a lot of different FFmpeg library combination we can add to our project. But we will add universal FFmpeg dependency which will work in all scenario and different device type.

Use FFmpeg to fetch media information πŸŽ₯

We can use FFmpeg utility function FFprobeKit to fetch media information. Now we will create some utility method to easily fetch media information.

Fetch media length πŸ“

There are many scenarios where we need to fetch video length to show in our project. Using FFmpeg, we can easily fetch all the media meta-data and use it in our project.

Below is the list of media information available in FFprobeKit media streams. You can change the duration parameter in above function to fetch any other information like media size, media name etc.

Using FFmpeg we can do a lot more like video cropping, trimming, compressing etc. FFmpeg provide vast no. of command to perform infinite operations on our media files. You can learn more about FFmpeg command here:

Use FFmpeg to perform video trim operation πŸ› 

Now use above created function to trim video.

await saveTrimmedVideo(
startValue: _startValue, //trimming start point
endValue: _endValue, //trimming start point
onSave: (String? outputPath) {
//Perform action on the trimmed video here });

You can create your own custom logic to perform on media. The possibilities are endless ∞

FFmpeg progress bar πŸ”„

Unfortunately, FFmpeg does not provide a callback to show the progress of the currently executed operation. So we cannot show a progress bar while our command is being executed. To fix this, we have created a utility method to get the progress of currently executed task.

Now let's show the progress. We will use the FFmpeg logs to generate progress status and show in the UI.

Thank you, and I hope this article helped you in some way. If you like the post, please support the article by sharing it. Have a nice day!πŸ‘‹

I am an mobile enthusiast πŸ“±. My expertise is in Flutter and Android development, with more than 5 years of experience in the industry.

I would love to write technical blogs for you. Writing blogs and helping people is what I crave for 😊 .You can contact me at my email(abdulrehman0796@gmail.com) for any collaboration πŸ‘‹

πŸ”— LinkedIn: https://www.linkedin.com/in/abdul-rehman-khilji/

--

--

Abdul Rehman

Mobile developer in love with Flutter and Android β™₯️