I have two videos that I want to trim, and then merge the trimmed output. They're all the same size/codec so I'd like to do that without re-encoding too much. But if I do:
ffmpeg -i clip1.mp4 -ss 1.2 -t 2.0 -c copy clip1.trimmed.mp4
ffmpeg -i clip2.mp4 -ss 0.2 -t 2.0 -c copy clip2.trimmed.mp4
ffmpeg -filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]'\
-map [v] -map [a] -c:v libx264 merge.mp4
The merged video has issues with audio/video synchronization. This doesn't happen if I replace -c copy
by -vcodec libx264
in the trimming command. Is it possible that by not re-encoding, something goes wrong with the timing?
The correct answer, from Mulvya:
ffmpeg -ss 1.2 -t 2.0 -i clip1.mp4 -ss 0.2 -t 2.0 -i clip2.mp4 \
-filter_complex '[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]" \
-map [v] -map [a] -c:v libx264 merge.mp4
In case that helps, I would add that the syntaxe to add clip specific filters is like:
ffmpeg -ss 1.2 -t 2.0 -i clip1.mp4 -ss 0.2 -t 2.0 -i clip2.mp4 \
-filter_complex '[0:v]scale=1920:960[v0]; [v0] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]" \
-map [v] -map [a] -c:v libx264 merge.mp4