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!
![Vibration API]()
Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user. One of those simple APIs the Vibration API. The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...
![Create a CSS Cube]()
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals. Add animation and you've got something really neat. Unfortunately each CSS cube tutorial I've read is a bit...
![Detect Vendor Prefix with JavaScript]()
Regardless of our position on vendor prefixes, we have to live with them and occasionally use them to make things work. These prefixes can be used in two formats: the CSS format (-moz-
, as in -moz-element
) and the JS format (navigator.mozApps
). The awesome X-Tag project has...
![Multiple Backgrounds with CSS]()
Anyone that's been in the web development industry for 5+ years knows that there are certain features that we should have had several years ago. One of those features is the HTML5 placeholder; we used JavaScript shims for a decade before placeholder came...
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.