FFmpeg Tutorial: How to combine multiple clips into one video with FFmpeg

0:00

Need to combine multiple

0:01

clips into one seamless video.

0:03

Whether you're merging

0:04

interviews, creating a

0:05

highlight reel or stitching a

0:07

simple shoot day, FFmpeg gives

0:09

you two ways to achieve this.

0:11

One, if all of the formats

0:12

and codecs are matching,

0:14

and another way, if they're

0:15

not, let's get into both.

0:18

Gonna have two different

0:19

ways to do this.

0:20

First one is if your video

0:21

files have the same codec

0:22

resolution, frame rate,

0:24

container, all that good

0:25

stuff, we're gonna be

0:26

working out of the multi

0:27

underscore, same folder here.

0:30

See this one?

0:31

Surfing righty.

0:34

Great.

0:34

So we're gonna concatenate

0:36

all these together.

0:37

The way to do that in

0:38

FFmpeg is you're gonna

0:39

create a text file and

0:42

that's gonna be our input

0:43

in our terminal for FFmpeg.

0:45

So there's a good shortcut

0:47

in Mac where you can right

0:50

click and hit option and

0:52

you can copy the four

0:53

items as path names.

0:54

And there are absolute paths.

0:56

Um, and then I'm just

0:57

gonna paste those here.

0:59

Um, you can automate this very

1:00

easily if you wanted to, the

1:02

creation of this text file.

1:03

But for kind of learning

1:05

purposes here, we're just

1:05

gonna do it manually.

1:07

So each one is gonna be file,

1:10

uh, single quote, the absolute

1:12

URL, or you could do relative.

1:13

But for this one, we're

1:14

gonna do, um, absolute.

1:17

I'm just gonna

1:18

highlight each one.

1:19

Put in single

1:20

quotes, put a file.

1:23

All right, then I'm gonna

1:25

hit command S for save.

1:28

Um, and so you see

1:28

here, it's all good.

1:31

So that's, this is

1:31

kind of what we want.

1:33

We're gonna go to

1:34

our terminal here.

1:35

Again, if you don't have

1:36

FFmpeg installed, um, you can

1:38

easily do, uh, brew, install

1:40

FFmpeg or builder from source.

1:42

Building it from source is a

1:43

little bit more convoluted.

1:46

Our command is gonna be

1:47

FFmpeg dash F for format.

1:50

And Concat is for

1:51

Concatenation Safe is a

1:53

way to pull in a text file

1:55

for security reasons, and

1:56

then Dash I is our input.

1:58

So I'm actually gonna copy

1:59

the path name here just for

2:02

an easier way of doing it.

2:03

I could also drag

2:04

it if I wanted to.

2:05

And then this is just

2:06

a stream copy, right?

2:07

So we're just stitching

2:08

it everything together.

2:09

So we're grabbing all streams.

2:11

I mean, we're just copying

2:12

them into our output files.

2:13

So I'm gonna put.

2:16

S underscore output .mp4

2:18

because that's what the

2:18

base format is here, right?

2:21

I'm gonna hit enter, let's

2:24

see, see what it outputted.

2:26

And it looks like

2:29

it all worked out.

2:30

So it is in the order

2:31

that you put it in,

2:32

um, in that text file.

2:34

But everything looks great.

2:36

And, uh, that's how you

2:38

stitch without re encoding.

2:40

And if they're all

2:41

the same format.

2:44

For our second section

2:46

of this, we're gonna

2:46

combine different kinds of

2:47

video files or different

2:48

flavors of video files.

2:50

Ones that have different

2:50

codecs or different frame

2:51

rates, different formats,

2:53

anything like that.

2:54

We have these two right here.

2:55

One's in 25 frames per

2:57

second, the other is in

2:57

30 frames per second.

3:00

So we have this one

3:02

and the surfing one.

3:03

So no text file for this.

3:05

We're just going to be doing

3:07

this in the terminal and we're

3:09

gonna have two inputs here.

3:11

And I'm just gonna

3:11

drag these over.

3:12

It's easier this way.

3:14

We're gonna do

3:15

our second input.

3:16

Great. So we have our two inputs

3:17

here now where you're

3:19

going to write a filter

3:22

map or a complex filter.

3:24

Gonna be two quotes and

3:26

it's gonna be a bunch

3:27

of square brackets and a

3:29

bunch of things that might

3:30

look a little foreign,

3:31

but just bear with me.

3:32

That is going to be the video

3:34

stream of the first input,

3:37

and we're gonna do the audio

3:38

stream of the first input.

3:40

Now we are going to do the

3:42

video stream of the second

3:43

input and then the audio

3:46

stream of the second input.

3:47

The one is for index one.

3:49

Then we are gonna tell

3:50

the filter to Concat.

3:52

The N is for the number

3:54

streams, V equals one, so two

3:57

streams into one video stream.

3:58

Then one audio stream,

4:01

pipe that into out.

4:03

It's almost like a variable

4:04

out V plus out A, which is

4:07

output video, output audio.

4:10

Close quotes there.

4:10

We're gonna map each one into

4:12

this new video, file out B,

4:17

and then map quotes, square

4:19

brackets out A, and then we're

4:22

gonna do D underscore output,

4:25

so for different, and then

4:26

we are going to run this.

4:27

Let's just make sure

4:29

looks good to me.

4:31

All right, let's run it.

4:37

And this one is encoding

4:38

as well as you see.

4:41

This is why it's taken a

4:42

little bit, but here we go.

4:44

Um, we do have to re-encode

4:46

just because they're different

4:47

formats, different codecs.

4:48

We wouldn't be able

4:49

to stream copy.

4:50

So let's check this one out.

4:52

That looks good.

4:53

That's the first file that

4:54

we, it's our first input.

4:57

And here's our second input.

4:59

So that's works for

5:00

kind of mismatched

5:01

clips, and that's it.

5:03

Now you can join video clips

5:04

in seconds with FFmpeg.

5:06

For more short, powerful media

5:08

tips, hit like and subscribe.

5:10

See you in the next one.