[FFmpeg-user] Lossless concatenation of 2 MP4 files with video and multiple audio streams plus subtitles and chapter markers

Rick Keniuk daddyo323 at gmail.com
Sat Jul 13 05:26:31 EEST 2024


I'm trying to lossless concatenate two MP4 files using FFMPEG. The files 
have 1 video stream, 2 audio streams, subtitle stream and chapter markers.

Here is the info for one file (the two files have identical stream 
configurations).

D:\Users\Rick\Videos>ffmpeg -i BOTRK1.mp4
ffmpeg version 7.0-full_build-www.gyan.dev Copyright (c) 2000-2024 the 
FFmpeg developers
   built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
   configuration: --enable-gpl --enable-version3 --enable-static 
--disable-w32threads --disable-autodetect --enable-fontconfig 
--enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp 
--enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib 
--enable-librist --enable-libsrt --enable-libssh --enable-libzmq 
--enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 
--enable-libaribb24 --enable-libaribcaption --enable-libdav1d 
--enable-libdavs2 --enable-libuavs3d --enable-libxevd --enable-libzvbi 
--enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 
--enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid 
--enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx 
--enable-mediafoundation --enable-libass --enable-frei0r 
--enable-libfreetype --enable-libfribidi --enable-libharfbuzz 
--enable-liblensfun --enable-libvidstab --enable-libvmaf 
--enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid 
--enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec 
--enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi 
--enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl 
--enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt 
--enable-libopencore-amrwb --enable-libmp3lame --enable-libshine 
--enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc 
--enable-libcodec2 --enable-libilbc --enable-libgsm 
--enable-libopencore-amrnb --enable-libopus --enable-libspeex 
--enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite 
--enable-libmysofa --enable-librubberband --enable-libsoxr 
--enable-chromaprint
   libavutil      59.  8.100 / 59.  8.100
   libavcodec     61.  3.100 / 61.  3.100
   libavformat    61.  1.100 / 61.  1.100
   libavdevice    61.  1.100 / 61.  1.100
   libavfilter    10.  1.100 / 10.  1.100
   libswscale      8.  1.100 /  8.  1.100
   libswresample   5.  1.100 /  5.  1.100
   libpostproc    58.  1.100 / 58.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'BOTRK1.mp4':
   Metadata:
     major_brand     : mp42
     minor_version   : 512
     compatible_brands: mp42dby1iso2avc1mp41
     creation_time   : 2024-07-12T13:34:48.000000Z
     encoder         : HandBrake 1.8.1 2024062200
   Duration: 01:21:21.75, start: 0.000000, bitrate: 3386 kb/s
   Chapters:
     Chapter #0:0: start 0.000000, end 411.186000
       Metadata:
         title           : Chapter 1
     Chapter #0:1: start 411.186000, end 663.805000
       Metadata:
         title           : Chapter 2
     Chapter #0:2: start 663.805000, end 937.645000
       Metadata:
         title           : Chapter 3
     Chapter #0:3: start 937.645000, end 1096.137000
       Metadata:
         title           : Chapter 4
     Chapter #0:4: start 1096.137000, end 1260.735000
       Metadata:
         title           : Chapter 5
     Chapter #0:5: start 1260.735000, end 1866.073000
       Metadata:
         title           : Chapter 6
     Chapter #0:6: start 1866.073000, end 1968.675000
       Metadata:
         title           : Chapter 7
     Chapter #0:7: start 1968.675000, end 2091.097000
       Metadata:
         title           : Chapter 8
     Chapter #0:8: start 2091.097000, end 2326.332000
       Metadata:
         title           : Chapter 9
     Chapter #0:9: start 2326.332000, end 2663.770000
       Metadata:
         title           : Chapter 10
     Chapter #0:10: start 2663.770000, end 3024.230000
       Metadata:
         title           : Chapter 11
     Chapter #0:11: start 3024.230000, end 3492.998000
       Metadata:
         title           : Chapter 12
     Chapter #0:12: start 3492.998000, end 3610.582000
       Metadata:
         title           : Chapter 13
     Chapter #0:13: start 3610.582000, end 3936.741000
       Metadata:
         title           : Chapter 14
     Chapter #0:14: start 3936.741000, end 4182.353000
       Metadata:
         title           : Chapter 15
     Chapter #0:15: start 4182.353000, end 4481.486000
       Metadata:
         title           : Chapter 16
     Chapter #0:16: start 4481.486000, end 4704.542000
       Metadata:
         title           : Chapter 17
     Chapter #0:17: start 4704.542000, end 4878.882000
       Metadata:
         title           : Chapter 18
     Chapter #0:18: start 4878.882000, end 4881.685000
       Metadata:
         title           : Chapter 19
   Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), 
yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 710x340 [SAR 32:27 
DAR 1136:459], 3027 kb/s, 23.99 fps, 120 tbr, 90k tbn (default)
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : VideoHandler
         vendor_id       : [0][0][0][0]
   Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 
stereo, fltp, 154 kb/s (default)
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : Stereo
         vendor_id       : [0][0][0][0]
   Stream #0:2[0x3](eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 
stereo, fltp, 192 kb/s
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : Stereo
         vendor_id       : [0][0][0][0]
       Side data:
         audio service type: main
   Stream #0:3[0x4](eng): Subtitle: dvd_subtitle (dvdsub) (mp4s / 
0x7334706D), 720x480, 3 kb/s (default)
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : SubtitleHandler
   Stream #0:4[0x5](eng): Data: bin_data (text / 0x74786574)
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : SubtitleHandler


I have tried the following simple concatenation command which worked 
perfectly only it outputs just the video and the first audio stream.

Video list file:

# videos.txt
file 'BOTRK1.mp4'
file 'BOTRK2.mp4'

and the FFMPEG command

ffmpeg -f concat -i videos.txt -c copy output.mp4

Is it possible to concatenate the 2 5-stream videos losslessly? I saw 
commands using video filters but I don't think they're lossless.  I 
think I'm just missing a couple switches to allow copying of the missing 
streams but I have no clue what they are.

This is the output from my concatenation that only output video and 1 audio.


D:\Users\Rick\Videos>ffmpeg -f concat -i videos.txt -c copy output.mp4
ffmpeg version 7.0-full_build-www.gyan.dev Copyright (c) 2000-2024 the 
FFmpeg developers
   built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
   configuration: --enable-gpl --enable-version3 --enable-static 
--disable-w32threads --disable-autodetect --enable-fontconfig 
--enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp 
--enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib 
--enable-librist --enable-libsrt --enable-libssh --enable-libzmq 
--enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 
--enable-libaribb24 --enable-libaribcaption --enable-libdav1d 
--enable-libdavs2 --enable-libuavs3d --enable-libxevd --enable-libzvbi 
--enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 
--enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid 
--enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx 
--enable-mediafoundation --enable-libass --enable-frei0r 
--enable-libfreetype --enable-libfribidi --enable-libharfbuzz 
--enable-liblensfun --enable-libvidstab --enable-libvmaf 
--enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid 
--enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec 
--enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi 
--enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl 
--enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt 
--enable-libopencore-amrwb --enable-libmp3lame --enable-libshine 
--enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc 
--enable-libcodec2 --enable-libilbc --enable-libgsm 
--enable-libopencore-amrnb --enable-libopus --enable-libspeex 
--enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite 
--enable-libmysofa --enable-librubberband --enable-libsoxr 
--enable-chromaprint
   libavutil      59.  8.100 / 59.  8.100
   libavcodec     61.  3.100 / 61.  3.100
   libavformat    61.  1.100 / 61.  1.100
   libavdevice    61.  1.100 / 61.  1.100
   libavfilter    10.  1.100 / 10.  1.100
   libswscale      8.  1.100 /  8.  1.100
   libswresample   5.  1.100 /  5.  1.100
   libpostproc    58.  1.100 / 58.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001bfac2521c0] Auto-inserting 
h264_mp4toannexb bitstream filter
Input #0, concat, from 'videos.txt':
   Duration: N/A, start: -0.044000, bitrate: 3376 kb/s
   Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, 
smpte170m/smpte170m/bt709, progressive), 710x340 [SAR 32:27 DAR 
1136:459], 3027 kb/s, 23.99 fps, 120 tbr, 90k tbn
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : VideoHandler
         vendor_id       : [0][0][0][0]
   Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 
stereo, fltp, 154 kb/s
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : Stereo
         vendor_id       : [0][0][0][0]
   Stream #0:2(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, stereo, 
fltp, 192 kb/s
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : Stereo
         vendor_id       : [0][0][0][0]
       Side data:
         audio service type: main
   Stream #0:3(eng): Subtitle: dvd_subtitle (dvdsub) (mp4s / 
0x7334706D), 720x480, 3 kb/s
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : SubtitleHandler
   Stream #0:4(eng): Data: bin_data (text / 0x74786574)
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : SubtitleHandler
Stream mapping:
   Stream #0:0 -> #0:0 (copy)
   Stream #0:1 -> #0:1 (copy)
Output #0, mp4, to 'output8.mp4':
   Metadata:
     encoder         : Lavf61.1.100
   Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, 
smpte170m/smpte170m/bt709, progressive), 710x340 [SAR 32:27 DAR 
1136:459], q=2-31, 3027 kb/s, 23.99 fps, 120 tbr, 90k tbn
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : VideoHandler
         vendor_id       : [0][0][0][0]
   Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 
stereo, fltp, 154 kb/s
       Metadata:
         creation_time   : 2024-07-12T13:34:48.000000Z
         handler_name    : Stereo
         vendor_id       : [0][0][0][0]
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001bfad7f08c0] Auto-inserting 
h264_mp4toannexb bitstream filter
[aost#0:1/copy @ 000001bfac25e640] Non-monotonic DTS; previous: 
234324992, current: 234323904; changing to 234324993. This may result in 
incorrect timestamps in the output file.
[aost#0:1/copy @ 000001bfac25e640] Non-monotonic DTS; previous: 
234324993, current: 234324928; changing to 234324994. This may result in 
incorrect timestamps in the output file.
[out#0/mp4 @ 000001bfac265ec0] video:3579725KiB audio:182906KiB 
subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 
0.198463%
size= 3770099KiB time=02:42:04.78 bitrate=3175.9kbits/s speed= 106x




More information about the ffmpeg-user mailing list