FFmpeg Tutorial: How to combine multiple clips into one video with FFmpeg
Need to combine multiple
clips into one seamless video.
Whether you're merging
interviews, creating a
highlight reel or stitching a
simple shoot day, FFmpeg gives
you two ways to achieve this.
One, if all of the formats
and codecs are matching,
and another way, if they're
not, let's get into both.
Gonna have two different
ways to do this.
First one is if your video
files have the same codec
resolution, frame rate,
container, all that good
stuff, we're gonna be
working out of the multi
underscore, same folder here.
See this one?
Surfing righty.
Great.
So we're gonna concatenate
all these together.
The way to do that in
FFmpeg is you're gonna
create a text file and
that's gonna be our input
in our terminal for FFmpeg.
So there's a good shortcut
in Mac where you can right
click and hit option and
you can copy the four
items as path names.
And there are absolute paths.
Um, and then I'm just
gonna paste those here.
Um, you can automate this very
easily if you wanted to, the
creation of this text file.
But for kind of learning
purposes here, we're just
gonna do it manually.
So each one is gonna be file,
uh, single quote, the absolute
URL, or you could do relative.
But for this one, we're
gonna do, um, absolute.
I'm just gonna
highlight each one.
Put in single
quotes, put a file.
All right, then I'm gonna
hit command S for save.
Um, and so you see
here, it's all good.
So that's, this is
kind of what we want.
We're gonna go to
our terminal here.
Again, if you don't have
FFmpeg installed, um, you can
easily do, uh, brew, install
FFmpeg or builder from source.
Building it from source is a
little bit more convoluted.
Our command is gonna be
FFmpeg dash F for format.
And Concat is for
Concatenation Safe is a
way to pull in a text file
for security reasons, and
then Dash I is our input.
So I'm actually gonna copy
the path name here just for
an easier way of doing it.
I could also drag
it if I wanted to.
And then this is just
a stream copy, right?
So we're just stitching
it everything together.
So we're grabbing all streams.
I mean, we're just copying
them into our output files.
So I'm gonna put.
S underscore output .mp4
because that's what the
base format is here, right?
I'm gonna hit enter, let's
see, see what it outputted.
And it looks like
it all worked out.
So it is in the order
that you put it in,
um, in that text file.
But everything looks great.
And, uh, that's how you
stitch without re encoding.
And if they're all
the same format.
For our second section
of this, we're gonna
combine different kinds of
video files or different
flavors of video files.
Ones that have different
codecs or different frame
rates, different formats,
anything like that.
We have these two right here.
One's in 25 frames per
second, the other is in
30 frames per second.
So we have this one
and the surfing one.
So no text file for this.
We're just going to be doing
this in the terminal and we're
gonna have two inputs here.
And I'm just gonna
drag these over.
It's easier this way.
We're gonna do
our second input.
Great. So we have our two inputs
here now where you're
going to write a filter
map or a complex filter.
Gonna be two quotes and
it's gonna be a bunch
of square brackets and a
bunch of things that might
look a little foreign,
but just bear with me.
That is going to be the video
stream of the first input,
and we're gonna do the audio
stream of the first input.
Now we are going to do the
video stream of the second
input and then the audio
stream of the second input.
The one is for index one.
Then we are gonna tell
the filter to Concat.
The N is for the number
streams, V equals one, so two
streams into one video stream.
Then one audio stream,
pipe that into out.
It's almost like a variable
out V plus out A, which is
output video, output audio.
Close quotes there.
We're gonna map each one into
this new video, file out B,
and then map quotes, square
brackets out A, and then we're
gonna do D underscore output,
so for different, and then
we are going to run this.
Let's just make sure
looks good to me.
All right, let's run it.
And this one is encoding
as well as you see.
This is why it's taken a
little bit, but here we go.
Um, we do have to re-encode
just because they're different
formats, different codecs.
We wouldn't be able
to stream copy.
So let's check this one out.
That looks good.
That's the first file that
we, it's our first input.
And here's our second input.
So that's works for
kind of mismatched
clips, and that's it.
Now you can join video clips
in seconds with FFmpeg.
For more short, powerful media
tips, hit like and subscribe.
See you in the next one.