[FFmpeg-user] Multiple parts of a video

Bo Berglund bo.berglund at gmail.com
Tue May 31 22:55:47 EEST 2022

On Tue, 31 May 2022 13:15:02 +0200, Michael Koch <astroelectronic at t-online.de>

>> So reading this thread I get the feeling that there is a way to use the list of
>> cut times in a *single ffmpeg command* to create the output mp4 file *without*
>> creating the list file and essentially doing everything in this single ffmpeg
>> command.
>I have a short example in chapter 2.57 of my book:

So I used the command that re-encodes the video from example 2.57 for an input
file of 64 minutes where the cuts sum to 44m33s

time ffmpeg -hide_banner \
-ss 25 -t 1100 -i input.mp4 \
-ss 1338 -t 265 -i input.u.mp4 \
-ss 1831 -t 573 -i input.u.mp4 \
-ss 2647 -t 735 -i input.u.mp4 \
-lavfi "concat=n=4:v=1:a=1" -an output.mp4

real    6m53.455s

So this took almost 7 minutes to cut out the 4 sections and concatenate them
onto the output file. I had to change :a=0 to :a=1 in order to get audio too.

This slower concatenation (compared to using -c copy as in example 2.56)
produces a much smoother video transition between cuts. No interruptions like I
have in my existing concat function, which uses copy.

But the downside is of course the long processing, using copy makes the process
run for 3-6 seconds only...

But it *is* a one-command ffmpeg concat of multiple sections in the same source
file onto an output file including audio....

I also tried to concat using the 2.56 example but with two files recorded from
the same stream but at different times.
Did not work at all, the first part plays OK but the second half is muted and
there are a lot of error output during the encoding, many-many lines like this:

[mp4 @ 0x5622ce1a0200] Non-monotonous DTS in output stream 0:0; previous:
81976537, current: 81940035; changing to 81976538. This may result in incorrect
timestamps in the output file.

Bo Berglund
Developer in Sweden

More information about the ffmpeg-user mailing list