0
votes

I want to extract video from multiple videos with ffmpeg. Normally, I could extract the video file from one large video file with the following command.

ffmpeg -ss 648 -t 29 -i /MatrixMovie.ts -f mpegts -pix_fmt yuv422p -c:v libx264 -preset ultrafast -map 0 snapshot.ts

But now I have 10 minutes of parts of this video file (MatrixMovie_part1.ts, MatrixMovie_part2.ts etc) instead of one large file. And the video that I want to extract starts on one of these parts and ends on the other.

My question is How to extract video from multiple videos with ffmpeg?

I've been dealing with ffmpeq for days but couldn't manage it. I would appreciate it if you could help. Thank you.

1

1 Answers

0
votes

You can concatenate all parts virtually together in FFmpeg:

./ffmpeg -i file1.ts -i file2.ts -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -ss 00:04 -t 11 out.ts

Short explanation:
-i <file> is added for each source file you have

Now we need to concat all files together in one filter -filter_complex. [0:v:0][0:a:0][1:v:0][1:a:0] defines all relevant inputs (first digit is the counter of the input file; v = video-stream, a = audio-stream; last digit 0 is to pick only one found stream. Add more [x:v:0][x:a:0] for each input file. The command concat=n=2:v=1:a=1 tells FFmpeg how to deal with all this streams (n=2 because of 2 inputs; increase this number for each input file; v=1 for one video; a=1 for one audio output). [outv][outa] are output names of the filter.

-map "[outv]" -map "[outa]" maps the output of the filter for further processing.

Now you have one virtual video/audio. E.g. if you have 2 input files with a duration of 10 seconds, the virtual stream is now 20 seconds long.

-ss 00:04 -t 11 you know already to seek and trim the video.