產生 ffmpeg concat 清單
使用指令如下
cd 0512_mp4_files
ls *.mp4 | xargs printf "file '%s'\n" "$1" > filelist.txt
合併用檔案清單 filelist.txt
file '140005.mp4'
file '140106.mp4'
file '140206.mp4'
file '140306.mp4'
file '140406.mp4'
file '140506.mp4'
file '140607.mp4'
file '140707.mp4'
file '140807.mp4'
file '140907.mp4'
執行下列指令合併的多個MP4檔案
使用指令
cd 0512_mp4_files
ffmpeg -f concat -i ./filelist.txt -c copy your_target.mp4
範例
$ ffmpeg -f concat -i ./filelist.txt -c copy 0512_all.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags=-fno-stack-check --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd408016200] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from './filelist.txt':
Duration: N/A, start: 0.000000, bitrate: 1328 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, 1300 kb/s, 20.02 fps, 20 tbr, 90k tbn, 180k tbc
Metadata:
creation_time : 1983-04-09T07:52:37.000000Z
handler_name : xsj_vid
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, stereo, fltp, 27 kb/s
Metadata:
creation_time : 1983-04-09T07:52:37.000000Z
handler_name : xsj_aud
Output #0, mp4, to '0512_all.mp4':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, q=2-31, 1300 kb/s, 20.02 fps, 20 tbr, 90k tbn, 90k tbc
Metadata:
creation_time : 1983-04-09T07:52:37.000000Z
handler_name : xsj_vid
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, stereo, fltp, 27 kb/s
Metadata:
creation_time : 1983-04-09T07:52:37.000000Z
handler_name : xsj_aud
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd408016200] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd409004800] Auto-inserting h264_mp4toannexb bitstream filter
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 1920672, current: 1920000; changing to 1920673. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 1920673, current: 1920160; changing to 1920674. This may result in incorrect timestamps in the output file.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd407800000] Auto-inserting h264_mp4toannexb bitstream filter
[concat @ 0x7fd408009800] DTS 16200000 < 16203870 out of order
...
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd409004800] Auto-inserting h264_mp4toannexb bitstream filter
[concat @ 0x7fd408009800] DTS 640980000 < 640988370 out of order
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:0; previous: 640988370, current: 640980000; changing to 640988371. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 113953720, current: 113952000; changing to 113953721. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:0; previous: 640988371, current: 640980900; changing to 640988372. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 113953721, current: 113952160; changing to 113953722. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:0; previous: 640988372, current: 640985400; changing to 640988373. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7fd407004a00] Non-monotonous DTS in output stream 0:1; previous: 113953722, current: 113953232; changing to 113953723. This may result in incorrect timestamps in the output file.
frame=144301 fps=11366 q=-1.0 Lsize= 1171225kB time=01:59:42.11 bitrate=1335.9kbits/s speed= 566x
video:1143434kB audio:24298kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.299121%