FFmpeg meets Flutter π€
--
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/