<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Malay Patel on Medium]]></title>
        <description><![CDATA[Stories by Malay Patel on Medium]]></description>
        <link>https://medium.com/@malay-dev?source=rss-a12a83066466------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UJV1vyYWCvZj4SsQSqqcdw.jpeg</url>
            <title>Stories by Malay Patel on Medium</title>
            <link>https://medium.com/@malay-dev?source=rss-a12a83066466------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 09 Jun 2026 05:06:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@malay-dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[How to merge audio and video in Flutter using FFmpeg?]]></title>
            <link>https://malay-dev.medium.com/how-to-merge-audio-and-video-in-flutter-using-ffmpeg-7bb33b5ac495?source=rss-a12a83066466------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bb33b5ac495</guid>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[malay-patel]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Malay Patel]]></dc:creator>
            <pubDate>Fri, 04 Aug 2023 18:16:38 GMT</pubDate>
            <atom:updated>2023-08-04T18:20:33.003Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey Fellows!<br>Are you someone who loves to develop and code? Interested in using <strong>Flutter and FFmpeg to merge audio into a video?</strong> Well, you’ve come to the right spot! <strong>In this blog, we’re diving deep into merging audio and video using FFmpeg in Flutter</strong>. Whether you’re experienced or just getting started, our easy-to-follow guides will help you make cool multimedia apps.</p><p>You’re about to enhance your Flutter projects and become a pro at mixing audio and video. Let’s start this coding journey together and open up a whole new world of possibilities. Get ready to blend, tweak, and craft with FFmpeg in Flutter—because your digital ideas deserve to look and sound amazing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*InOfyUW5W2IZFpn67Iy95A.png" /></figure><blockquote><strong>We will start setting up our project by adding packages that we will need to merge MP3 and MP4 files using FFmpeg</strong>.<br><a href="https://pub.dev/packages/ffmpeg_kit_flutter"><strong><em>ffmpeg_kit_flutter</em></strong></a>:- This package will help us run FFmpeg commands in Flutter, using which we will merge MP3 with MP4.<br><a href="https://pub.dev/packages/path_provider"><strong><em>path_provider</em></strong></a>:- Path Provider will help us get directory paths using which we can fetch the audio and video files and also save our output file.<br><a href="https://pub.dev/packages/permission_handler"><strong>permission_handler</strong></a>:- We will be needing this package so that we can get permission to read or write user’s files.</blockquote><p><strong><em>pubspec.yaml </em></strong>:-</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  ffmpeg_kit_flutter: ^x.x.x  # Replace with the latest version<br>  path_provider: ^x.x.x  # Replace with the latest version<br>  permission_handler: ^x.x.x  # Replace with the latest version</pre><p>Now we can start coding by making three functions that will help us <strong>merge audio and video files</strong></p><p>First of all, we will <strong>request storage permission</strong> from the user so that we can access their mp3 and mp4 files</p><pre>  PermissionStatus _permissionStatus = PermissionStatus.undetermined;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _requestStoragePermission();<br>  }<br><br>  Future&lt;void&gt; _requestStoragePermission() async {<br>    final status = await Permission.storage.request();<br>    setState(() {<br>      _permissionStatus = status;<br>    });<br>  }</pre><p>Then we will get the path where we want to get our mp3 and mp4 files and save our output.mp4 file</p><pre>  Future&lt;String&gt; _getAudioFilePath() async {<br>    final directory = await getTemporaryDirectory();<br>    return &#39;${directory.path}/audio.mp3&#39;; // Replace with your audio file path<br>  }<br><br>  Future&lt;String&gt; _getVideoFilePath() async {<br>    final directory = await getTemporaryDirectory();<br>    return &#39;${directory.path}/video.mp4&#39;; // Replace with your video file path<br>  }<br><br>  Future&lt;String&gt; _getOutputFilePath() async {<br>    final directory = await getTemporaryDirectory();<br>    return &#39;${directory.path}/output.mp4&#39;; // Replace with your desired output file path<br>  }</pre><p>Now we will be coding the main function where our <strong>video and the audio will be merged using FFmpeg</strong></p><pre>  Future&lt;void&gt; _mergeAudioAndVideo() async {<br>    if (_permissionStatus != PermissionStatus.granted) {<br>      print(&#39;Storage permission not granted.&#39;);<br>      return;<br>    }<br><br>    final audioPath = await _getAudioFilePath();<br>    final videoPath = await _getVideoFilePath();<br>    final outputPath = await _getOutputFilePath();<br><br>    final command =<br>        &#39;-i $videoPath -i $audioPath -c:v copy -c:a aac -strict experimental $outputPath&#39;;<br><br>    final executionId = await FFmpegKit.executeAsync(command);<br>    final returnCode = await FFmpegKitConfig.getLastReturnCode();<br><br>    if (returnCode == ReturnCode.SUCCESS) {<br>      print(&#39;Merge successful&#39;);<br>    } else {<br>      print(&#39;Merge failed&#39;);<br>    }<br>  }</pre><p>Now let’s create a <strong>basic UI</strong> using which the user will trigger the function and the merging will start</p><pre>@override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Audio and Video Merge Demo&#39;),<br>      ),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: _mergeAudioAndVideo,<br>          child: Text(&#39;Merge Audio and Video&#39;),<br>        ),<br>      ),<br>    );<br>  }</pre><p>This is it! You merged an audio file and a video file using Flutter and FFmpeg.</p><p><strong>You can find the whole code here:</strong></p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:ffmpeg_kit_flutter/ffmpeg_kit.dart&#39;;<br>import &#39;package:path_provider/path_provider.dart&#39;;<br>import &#39;package:permission_handler/permission_handler.dart&#39;;<br><br>class AudioVideoMergeDemo extends StatefulWidget {<br>  @override<br>  _AudioVideoMergeDemoState createState() =&gt; _AudioVideoMergeDemoState();<br>}<br><br>class _AudioVideoMergeDemoState extends State&lt;AudioVideoMergeDemo&gt; {<br>  PermissionStatus _permissionStatus = PermissionStatus.undetermined;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _requestStoragePermission();<br>  }<br><br>  Future&lt;void&gt; _requestStoragePermission() async {<br>    final status = await Permission.storage.request();<br>    setState(() {<br>      _permissionStatus = status;<br>    });<br>  }<br><br>  Future&lt;void&gt; _mergeAudioAndVideo() async {<br>    if (_permissionStatus != PermissionStatus.granted) {<br>      print(&#39;Storage permission not granted.&#39;);<br>      return;<br>    }<br><br>    final audioPath = await _getAudioFilePath();<br>    final videoPath = await _getVideoFilePath();<br>    final outputPath = await _getOutputFilePath();<br><br>    final command =<br>        &#39;-i $videoPath -i $audioPath -c:v copy -c:a aac -strict experimental $outputPath&#39;;<br><br>    final executionId = await FFmpegKit.executeAsync(command);<br>    final returnCode = await FFmpegKitConfig.getLastReturnCode();<br><br>    if (returnCode == ReturnCode.SUCCESS) {<br>      print(&#39;Merge successful&#39;);<br>    } else {<br>      print(&#39;Merge failed&#39;);<br>    }<br>  }<br><br>  Future&lt;String&gt; _getAudioFilePath() async {<br>    final directory = await getTemporaryDirectory();<br>    return &#39;${directory.path}/audio.mp3&#39;; // Replace with your audio file path<br>  }<br><br>  Future&lt;String&gt; _getVideoFilePath() async {<br>    final directory = await getTemporaryDirectory();<br>    return &#39;${directory.path}/video.mp4&#39;; // Replace with your video file path<br>  }<br><br>  Future&lt;String&gt; _getOutputFilePath() async {<br>    final directory = await getTemporaryDirectory();<br>    return &#39;${directory.path}/output.mp4&#39;; // Replace with your desired output file path<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Audio and Video Merge Demo&#39;),<br>      ),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: _mergeAudioAndVideo,<br>          child: Text(&#39;Merge Audio and Video&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>void main() {<br>  runApp(MaterialApp(<br>    home: AudioVideoMergeDemo(),<br>  ));<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bb33b5ac495" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>