I want to merge two or three MP4 videos with MPEG-4 AVC video codec and MP3 (sometimes MP3 Surround) audio codecs. Both audio and video can have different bitrate. If it will be possible, without transcoding. I already tried using FFmpeg, MP4Box and AviDemux, but with no success. I'm looking for a solution that can be executed using only command line.
Every movie is encoded by AviDemux with Two-Pass option.
There is how I tried to do it with AviDemux:
avidemux --force-alt-h264 --load video1.mp4 --append video2.mp4 --output-format MP4 --save output.mp4 --quit
There how with FFmpeg:
ffmpeg -y -f concat -i list.txt -c copy output.mp4
And how with MP4Box:
MP4Box -cat video1.mp4 -cat video2.mp4 -new output.mp4
Sometimes it failed at all, but sometimes it gave me video with first file playing good, but the second file was corrupted.
avprobe command for the two files return this:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ad.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
title : ad.mp4
encoder : Lavf52.78.3
Duration: 00:00:03.28, start: 0.000000, bitrate: 446 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 312 kb/s, 25 fps, 25 tbr, 25025 tbn, 50 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
Stream #0.1(und): Audio: mp3, 48000 Hz, 2 channels, s16p, 126 kb/s
Metadata:
creation_time : 1970-01-01 00:00:00
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ad-chipmunkove.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01 00:00:00
title : ad-chipmunkove.mp4
encoder : Lavf52.78.3
Duration: 00:00:29.96, start: 0.000000, bitrate: 2946 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 2813 kb/s, 25 fps, 25 tbr, 25025 tbn, 50 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
Stream #0.1(und): Audio: mp3, 48000 Hz, 2 channels, s16p, 127 kb/s
Metadata:
creation_time : 1970-01-01 00:00:00
And FFmpeg merging this:
[concat @ 0xb03ae40] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'list.txt':
Duration: 00:00:00.00, start: 0.000000, bitrate: 440 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 312 kb/s, 25 fps, 25 tbr, 25025 tbn, 50 tbc
Stream #0:1: Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, s16p, 126 kb/s
Output #0, mp4, to 'output.mp4':
Metadata:
encoder : Lavf55.41.100
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 312 kb/s, 25 fps, 25025 tbn, 25025 tbc
Stream #0:1: Audio: mp3 (i[0][0][0] / 0x0069), 48000 Hz, stereo, 126 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 831 fps=0.0 q=-1.0 Lsize= 10961kB time=00:00:33.23 bitrate=2702.0kbits/s
video:10414kB audio:518kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.266208%
The second part of the result video looks this way, but audio is working fine.