FFmpeg Tutorial: How to quickly merge audio and video files with FFmpeg

0:00

Whether you're localizing

0:01

for global audiences or

0:02

just playing around with

0:04

multi-language content,

0:05

ffmpeg makes it super

0:07

seamless to swap or add an

0:09

audio track to your video.

0:11

In this quick guide, I'll

0:12

show you how to add a foreign

0:14

language audio track to your

0:15

videos using only command line

0:18

and no video editor required.

0:20

Let's get into it.

0:22

We're gonna have a couple use

0:23

cases here, but the first one

0:25

is going to completely replace

0:26

the English with the French.

0:28

So I have our terminal

0:29

loaded up here as well

0:30

as our two files here.

0:32

So our first one is going to

0:33

be the original video file.

0:35

Darius, you talked earlier,

0:36

and as you hear it's in

0:37

English and web component

0:39

players can be dropped

0:40

right into your application.

0:41

Perfect.

0:41

Another tutorial, did you

0:43

know that you can also,

0:44

and then we're gonna, uh,

0:45

take a look at the, the

0:46

French Dub diversion or

0:48

translated version here.

0:55

Great.

0:56

First things first

0:57

is ffmpeg, right?

0:59

And then I stands for input.

1:01

So we're gonna do our first

1:02

input, which is video mp4,

1:05

and then we're gonna do our

1:06

second input of French mp4.

1:11

Next thing, is gonna be

1:13

"-c:v" So C stands for codec

1:16

and V stands for video.

1:18

That's how we select the

1:19

video codec and we're gonna

1:20

stream copy that because

1:22

we don't need to encode it.

1:23

Next thing we're gonna map

1:25

both the streams into the

1:26

locations that we want.

1:27

So first thing is gonna

1:29

be the video stream.

1:30

So we're just gonna take

1:31

the stream index zero,

1:32

which is video mp4.

1:34

We're gonna take the

1:34

video stream of that V

1:37

and the destination index

1:38

is going to also be zero.

1:41

So the first stream, right?

1:44

Our second map, uh, parameter

1:46

here is gonna be one, which

1:49

is the one is index, one of

1:51

inputs, which is French .m4a.

1:54

The audio of that, there's

1:55

only audio, and then we're

1:57

gonna have that be in the

1:59

index zero destination.

2:01

So going along to this and

2:05

for the audio, we are just

2:06

going to also stream copy.

2:09

So if we wanted to, I

2:10

could have just done

2:11

dash C and just copy.

2:13

But for learning purposes

2:14

it's a little easier this way.

2:15

Um, replaced time .mp4,

2:20

that's gonna be our, our

2:21

output command ,right?

2:22

We're gonna run it.

2:23

Hit enter.

2:25

All right.

2:26

We'll see it here.

2:28

Done.

2:28

Let's take a listen.

2:34

Perfect.

2:34

And if we wanted to see

2:35

that it was just one.

2:38

I wanna audio stream.

2:39

You can see here there's

2:40

just one, this is the, the

2:41

video here and then the,

2:43

the audio here as well.

2:45

That's the first use case,

2:46

which is just replacing

2:48

the original audio track.

2:52

Now we're onto use case

2:53

two, which is just to add an

2:55

additional audio track and

2:56

embed that, um, in the .mp4.

2:59

So we have a replace

3:00

one here, but again,

3:01

same two assets here.

3:04

And we are going to do

3:05

something very similar.

3:06

So if ffmpeg, of course

3:08

video .mp4 is our first

3:11

and then French .m4a.

3:15

And then we are gonna map

3:16

both of the audio streams as

3:18

well as the video stream here.

3:19

"0:v" is just selecting

3:22

all video streams

3:23

or the video stream.

3:24

Um, and then we're gonna

3:25

map all audio streams on

3:28

the first input, and then

3:29

we're gonna map all audio

3:31

streams on the second input.

3:33

And then in this case,

3:34

we are just gonna stream

3:36

copy, both or all.

3:38

And we're gonna call

3:39

this "multilang," right?

3:42

So first input, second

3:44

input are selecting the

3:45

video stream, selecting the

3:47

auto stream on the first

3:49

input, selecting the audio

3:50

stream on the second input.

3:51

And we're gonna copy

3:52

all of them together.

3:54

Okay?

3:54

We're gonna run it.

3:57

Um, when we play it, it will

3:59

likely, yeah, you won't be

4:02

able to, it will kind of

4:04

merge them both together.

4:06

But for this purpose, if we

4:09

wanted to probe it and see,

4:14

you see you have both.

4:15

So in some players they

4:17

might play 'em together

4:18

like QuickTime here.

4:19

Um, but.

4:21

These have both embedded here.

4:23

Now, let's see, let's

4:24

see if we wanted to

4:25

use like something

4:25

like VLC and play it.

4:27

Darius, you talked

4:28

earlier this week

4:29

about how our iframe.

4:31

All right, you can

4:31

just hear the English.

4:32

Perfect.

4:33

But if I wanted to

4:34

select a different

4:35

audio track, hit two.

4:40

And we hear the French,

4:42

and that's use case two,

4:43

and that's how you add

4:44

foreign language audio

4:45

tracks to your videos.

4:47

Great for localization,

4:48

accessibility, AI workflows,

4:50

or just giving your

4:51

content a broader reach.