To concat two mp4 or ts files (I've both formats) ffmpeg offers some calls that I've tried. Both "concat protocol" (for h264 TS files) and "Concat demuxer" (for h264 PS files) produce artifacts that are unpleasant to watch:
- Concat protocol with AVC (MPEG-TS - High profile) pixelates about 5 frames during the transition
- Concat demux with AVC (MPEG-PS - High Profile) skips frames and mixes some frames from the second clip into the first.
My goal was to copy the packages, not to remux them. So the calls were for the concat protocol
ffmpeg -i "concat:clip1.ts|clip2.ts" -c copy out.m2t
and the concat demuxer:
ffmpeg -hide_banner -y -f concat -safe 0 -i merge.txt -c copy out.mp4
Below the codec information of the two clips:
ffmpeg -n -i "clip1.mp4" -i "clip2.mp4"
ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.3.0 (Arch Linux 9.3.0-1)
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
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
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 01:28:05.12, start: 0.000000, bitrate: 8714 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 8253 kb/s, 50 fps, 50 tbr, 90k tbn, 100 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(deu): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, stereo, fltp, 448 kb/s (default)
Metadata:
handler_name : SoundHandler
Side data:
audio service type: main
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'clip2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:03:05.68, start: 0.000000, bitrate: 8680 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 8223 kb/s, 50 fps, 50 tbr, 90k tbn, 100 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(deu): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, stereo, fltp, 448 kb/s (default)
Metadata:
handler_name : SoundHandler
Side data:
audio service type: main
The "cat" option does not work for codecs with timestamps (which AVC/h264 has). Since I'm reluctant to remux the clips I wonder if there is another way to achieve a clean merge
mp4 is not mpeg. Thus, ffmpeg requires mapping.
To use ffmpeg to concat various a/v files, enter the following in terminal:
ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \ -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \ -map "[outv]" -map "[outa]" output.mkv
notes . If all files are mp4, them change the file extensions to mp4. . If more than three input files (eg 4), then change n=3 to n=4. If 2 files, then n=2. etc.