Join Audio and video on the command line

Posted by Andrew Denner on September 24, 2021 · 1 min read

Sometimes you just need to overlay an audio file across a video, and you don’t want to waste time messing around with the gui.

ffmpeg is the answer to all your problems (and likely will be the cause of several more… but that is a story for another post.)

Installation is quite simple (assuming a debian based os)

sudo apt update
sudo apt install ffmpeg

After the install process it is as simple as using the following command:

ffmpeg -i audiofile.mp4 -i videofile.mp4 -c:v copy -c:a copy outfile.mp4

or if you want to mess with transcodeing along the way:

ffmpeg -i audiofile.mp4 -i videofile.mp4 -c:v libx265 -c:a copy -x265-params crf=28 outfile.mp4

where libx265 will do h265 based encoding at at a slightly reduced than average crf quality rate (makes the end file a bit smaller)