3

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.

  • How were the files generated? Exactly the same encoder and encoding settings just with a different bitrate? Or from different settings? – slhck Jun 26 '14 at 17:07
  • They're encoded with AviDemux. Same resolution, same FPS, others are same, too. Just different bitrate. – Jacob Jun 26 '14 at 17:12
  • Generally it's possible if all other settings are the same, and if the sequences all start with an I-frame (or IDR-frame, to be more precise). I'm not sure about the MP3 part. MP3 is not supported in an MP4 container, I think. – slhck Jun 26 '14 at 17:20
  • @slhck MP3 is supported, everything is working fine on every device I can imagine – Xbox 360, Android, Windows Phone and Windows. – Jacob Jun 26 '14 at 17:25
0

Concatenating MP4 files, even with different bitrates, should work. That is the basic assumption of HTTP adaptive streaming using MPEG-DASH. If the decoder configuration is exactly the same, it is kept as is. If not exactly the same (but compatible), the sample description box stsd will have multiple entries.

For MP4Box, this looks like a bug. I suggest you file an issue here with links to some example files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.