Combine Audio and Video with ffmpeg
We have audio. We have video. We appreciate each of those media on their own but you can create an awesome work of art if you combine the two. After all, how could you watch a sports highlight video without setting the visuals to some obscure techno track? Blasphemy.
My favorite A/V utility, ffmpeg, allows you to merge an audio file and a video file into one brilliant piece of art:
ffmpeg -i video.mp4 -i audio.m4a -c:v copy -c:a copy output.mp4
You can even use an animated GIF for the video piece:
ffmpeg -i video.gif -i audio.m4a -c:v copy -c:a copy output.mp4
Banter aside, there are many good cases for combining an audio track with a video track, many examples being seen on YouTube. Happy media creation!
![7 Essential JavaScript Functions]()
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener
and attachEvent
. Times have changed but there are still a few functions each developer should...
![I’m an Impostor]()
This is the hardest thing I've ever had to write, much less admit to myself. I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life. All of those feelings were very...
![CSS Gradients]()
With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements. CSS gradients are another step in that direction. Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...
![Basic AJAX Requests Using MooTools 1.2]()
AJAX has become a huge part of the modern web and that wont change in the foreseeable future. MooTools has made AJAX so simple that a rookie developer can get their dynamic pages working in no time.
Step 1: The XHTML
Here we define two links...
There is a Firefox extension for this if anybody prefers UI over command line, https://addons.mozilla.org/en-US/firefox/addon/media-converter-and-muxer
If you don’t want to re-encode audio and video, you can use following command:
It will execute a lot faster.
Updated! Thank you!
You can specify to copy both at once like this:
This works like charm and looks few flags shorter too.
Hi David,
Nice article. Would these same commands work efficiently on android too?
We have a mute video to which we hope to add audio recorded from phone.
Any guidance would be great.
Can’t find ffmpeg in a zip file. Any other similar tool that opens in Windows?
I’m not a programmer so I’m sort of confused and frustrated at what I’m looking at. I have no idea how to use this lol
Here is an example batch file that you can drag the two files onto to do the joining, delete the two files and rename to the original. (drag by the mp4 file)
where do we keep ffmpeg.exe file and that audio and video files to whom we merge.