h.264 - Concatenate two mp4 files using ffmpeg -
i'm trying concatenate 2 mp4 files using ffmpeg. need automatic process hence why chose ffmpeg. i'm converting 2 files .ts files , concatenating them , trying encode concated .ts file. files h264 , aac encoded , i'm hoping keep quality same or close original possible.
ffmpeg -i part1.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part1.ts ffmpeg -i part2.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part2.ts cat part1.ts part2.ts > parts.ts ffmpeg -y -i parts.ts -acodec copy -ar 44100 -ab 96k -coder ac -vbsf h264_mp4toannexb parts.mp4
unfortunately i'm getting following error message coming ffmpeg during encoding:
[h264 @ 0x1012600]sps_id out of range [h264 @ 0x1012600]non-existing sps 0 referenced in buffering period [h264 @ 0x1012600]sps_id out of range [h264 @ 0x1012600]non-existing sps 0 referenced in buffering period [null @ 0x101d600]error, non monotone timestamps 13779431 >= 13779431kbits/s av_interleaved_write_frame(): error while opening file
this happens half way through encoding makes me think can't concat 2 .ts files , have work. appreciated.
ffmpeg has 3 concat methods. (in windows, use double quotes "
)
concat protocol
ffmpeg -i 'concat:input1|input2' -codec copy output
concat video filter
ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv \ -filter_complex '[0:0] [0:1] [1:0] [1:1] [2:0] [2:1] concat=n=3:v=1:a=1 [v] [a]' \ -map '[v]' -map '[a]' output.mkv
note method performs re-encode.
concat demuxer
$ cat mylist.txt file '/path/to/file1' file '/path/to/file2' file '/path/to/file3' $ ffmpeg -f concat -i mylist.txt -c copy output
for windows:
(echo file ../../../../1.mp4 & echo file ../../../../2.mp4 )>%tmp%/list.txt ffmpeg -safe 0 -f concat -i %tmp%/list.txt -c copy c:/output.mp4
which 1 use
- concat protocol: use formats support file level concatenation (mpeg-1, mpeg-2 ps, dv).
- concat filter: use if need re-encode such when applying filters.
- concat demuxer: use when want avoid re-encode , format not support file level concatenation.
if in doubt try concat demuxer.
Comments
Post a Comment