FFmpeg Tutorial: How to quickly merge audio and video files with FFmpeg
Whether you're localizing
for global audiences or
just playing around with
multi-language content,
ffmpeg makes it super
seamless to swap or add an
audio track to your video.
In this quick guide, I'll
show you how to add a foreign
language audio track to your
videos using only command line
and no video editor required.
Let's get into it.
We're gonna have a couple use
cases here, but the first one
is going to completely replace
the English with the French.
So I have our terminal
loaded up here as well
as our two files here.
So our first one is going to
be the original video file.
Darius, you talked earlier,
and as you hear it's in
English and web component
players can be dropped
right into your application.
Perfect.
Another tutorial, did you
know that you can also,
and then we're gonna, uh,
take a look at the, the
French Dub diversion or
translated version here.
Great.
First things first
is ffmpeg, right?
And then I stands for input.
So we're gonna do our first
input, which is video mp4,
and then we're gonna do our
second input of French mp4.
Next thing, is gonna be
"-c:v" So C stands for codec
and V stands for video.
That's how we select the
video codec and we're gonna
stream copy that because
we don't need to encode it.
Next thing we're gonna map
both the streams into the
locations that we want.
So first thing is gonna
be the video stream.
So we're just gonna take
the stream index zero,
which is video mp4.
We're gonna take the
video stream of that V
and the destination index
is going to also be zero.
So the first stream, right?
Our second map, uh, parameter
here is gonna be one, which
is the one is index, one of
inputs, which is French .m4a.
The audio of that, there's
only audio, and then we're
gonna have that be in the
index zero destination.
So going along to this and
for the audio, we are just
going to also stream copy.
So if we wanted to, I
could have just done
dash C and just copy.
But for learning purposes
it's a little easier this way.
Um, replaced time .mp4,
that's gonna be our, our
output command ,right?
We're gonna run it.
Hit enter.
All right.
We'll see it here.
Done.
Let's take a listen.
Perfect.
And if we wanted to see
that it was just one.
I wanna audio stream.
You can see here there's
just one, this is the, the
video here and then the,
the audio here as well.
That's the first use case,
which is just replacing
the original audio track.
Now we're onto use case
two, which is just to add an
additional audio track and
embed that, um, in the .mp4.
So we have a replace
one here, but again,
same two assets here.
And we are going to do
something very similar.
So if ffmpeg, of course
video .mp4 is our first
and then French .m4a.
And then we are gonna map
both of the audio streams as
well as the video stream here.
"0:v" is just selecting
all video streams
or the video stream.
Um, and then we're gonna
map all audio streams on
the first input, and then
we're gonna map all audio
streams on the second input.
And then in this case,
we are just gonna stream
copy, both or all.
And we're gonna call
this "multilang," right?
So first input, second
input are selecting the
video stream, selecting the
auto stream on the first
input, selecting the audio
stream on the second input.
And we're gonna copy
all of them together.
Okay?
We're gonna run it.
Um, when we play it, it will
likely, yeah, you won't be
able to, it will kind of
merge them both together.
But for this purpose, if we
wanted to probe it and see,
you see you have both.
So in some players they
might play 'em together
like QuickTime here.
Um, but.
These have both embedded here.
Now, let's see, let's
see if we wanted to
use like something
like VLC and play it.
Darius, you talked
earlier this week
about how our iframe.
All right, you can
just hear the English.
Perfect.
But if I wanted to
select a different
audio track, hit two.
And we hear the French,
and that's use case two,
and that's how you add
foreign language audio
tracks to your videos.
Great for localization,
accessibility, AI workflows,
or just giving your
content a broader reach.