I have list of video files (loaded from database), each with start and end time of requested interval:
# file begin end
v1.mp4 1:01 2:01
v2.mp4 3:02 3:32
v3.mp4 2:03 5:23
And I need to create single video file containing these intervals:
[0:00]---v1---[2:00]---v2---[2:30]---v3---[5:50]
I preffer usig ffmpeg, since it is installed on server. Caller program is written in PHP.
It is easy to cut one input to one output (argument escaping removed for clarity):
exec("ffmpeg -ss $begin -i $input_file -ss $begin -c copy $output_file");
I there any easier way than executing ffmpeg for each interval and then execute it once more to concatenate prepared clips together? I really do not like to have a lot of temporary files or dealing with complex process handling.
1
Solution #1:
ffmpeg -ss 1:01 -t 60 -i v1.mp4 -ss 3:02 -t 30 -i v2.mp4 -ss 2:03 -t 200 -i v3.mp4
-filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1"
-y mixed.mp4
Solution #2:
ffmpeg -i v1.mp4 -i v2.mp4 -i v3.mp4 -filter_complex "
[0:v]trim=61:121,setpts=PTS-STARTPTS[v1];
[0:a]atrim=61:121,asetpts=PTS-STARTPTS[a1];
[1:v]trim=182:212,setpts=PTS-STARTPTS[v2];
[1:a]atrim=182:212,asetpts=PTS-STARTPTS[a2];
[2:v]trim=123:323,setpts=PTS-STARTPTS[v3];
[2:a]atrim=123:323,asetpts=PTS-STARTPTS[a3];
[v1][a1][v2][a2][v3][a3]concat=n=3:v=1:a=1[v][a]"
-map "[v]" -map "[a]" -y mixed.mp4
2