Appending MP4s loses sound from second file

1

When I try to join two MP4s together using ffmpeg, the first file plays fine and has sound, but the second one loses all sound and becomes a lot choppier.

I encoded both the files from MKVs using Handbrake, and I used absolutely identical settings.

I've been working on this for about 14 hours and I just have no idea what I could do. Any ideas?

EDIT: Here are my commands and output:

Command: ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts

Output:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 17 2013 20:00:17 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2013-08-06 07:16:18
    encoder         : HandBrake 0.9.9 2013051800
  Duration: 00:57:27.65, start: 0.000000, bitrate: 561 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 512x384 [SAR 1:1 DAR 4:3], 473 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc
    Metadata:
      creation_time   : 2013-08-06 07:16:18
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 82 kb/s
    Metadata:
      creation_time   : 2013-08-06 07:16:18
Output #0, mpegts, to 'intermediate1.ts':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf54.63.104
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 512x384 [SAR 1:1 DAR 4:3], q=2-31, 473 kb/s, 30 fps, 90k tbn, 90k tbc
    Metadata:
      creation_time   : 2013-08-06 07:16:18
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, 82 kb/s
    Metadata:
      creation_time   : 2013-08-06 07:16:18
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[adts @ 0x7fad9b821800] Encoder did not produce proper pts, making some up.
frame= 7555 fps=0.0 q=-1.0 size=   19456kB time=00:04:11.93 bitrate= 632.6kbits/frame=15468 fps=15382 q=-1.0 size=   35385kB time=00:08:35.76 bitrate= 562.0kbitframe=24569 fps=16108 q=-1.0 size=   58371kB time=00:13:39.06 bitrate= 583.8kbitframe=38483 fps=18998 q=-1.0 size=   93146kB time=00:21:22.99 bitrate= 594.7kbitframe=49764 fps=19691 q=-1.0 size=  125242kB time=00:27:39.15 bitrate= 618.4kbitframe=57427 fps=18970 q=-1.0 size=  145969kB time=00:31:54.67 bitrate= 624.5kbitframe=69520 fps=19544 q=-1.0 size=  174084kB time=00:38:37.58 bitrate= 615.3kbitframe=75654 fps=18647 q=-1.0 size=  192548kB time=00:42:02.19 bitrate= 625.4kbitframe=78126 fps=17100 q=-1.0 size=  199829kB time=00:43:24.58 bitrate= 628.5kbitframe=82251 fps=16227 q=-1.0 size=  212075kB time=00:45:42.23 bitrate= 633.5kbitframe=87163 fps=15341 q=-1.0 size=  224289kB time=00:48:25.93 bitrate= 632.3kbitframe=91012 fps=14715 q=-1.0 size=  237568kB time=00:50:34.15 bitrate= 641.4kbitframe=96450 fps=14248 q=-1.0 size=  252123kB time=00:53:35.49 bitrate= 642.3kbitframe=103130 fps=14160 q=-1.0 size=  266333kB time=00:57:18.13 bitrate= 634.6kbiframe=103426 fps=14187 q=-1.0 Lsize=  266833kB time=00:57:27.65 bitrate= 634.0kbits/s    
video:199222kB audio:34638kB subtitle:0 global headers:0kB muxing overhead 14.099408%

Command: ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts

Output:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 17 2013 20:00:17 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2013-08-06 12:15:23
    encoder         : HandBrake 0.9.9 2013051800
  Duration: 00:03:16.46, start: 0.000000, bitrate: 652 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 512x384, 521 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Metadata:
      creation_time   : 2013-08-06 12:15:23
    Stream #0:1(jpn): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s
    Metadata:
      creation_time   : 2013-08-06 12:15:23
Output #0, mpegts, to 'intermediate2.ts':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf54.63.104
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 512x384, q=2-31, 521 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
    Metadata:
      creation_time   : 2013-08-06 12:15:23
    Stream #0:1(jpn): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 125 kb/s
    Metadata:
      creation_time   : 2013-08-06 12:15:23
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[adts @ 0x7f80ec03b600] Encoder did not produce proper pts, making some up.
frame= 5887 fps=0.0 q=-1.0 Lsize=   17671kB time=00:03:16.46 bitrate= 736.8kbits/s    
video:12502kB audio:3020kB subtitle:0 global headers:0kB muxing overhead 13.845737%

Command: ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4

Output:

ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 17 2013 20:00:17 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mpegts @ 0x7ff718806600] max_analyze_duration 5000000 reached at 5014800 microseconds
Input #0, mpegts, from 'concat:intermediate1.ts|intermediate2.ts':
  Duration: 00:03:16.44, start: 1.400000, bitrate: 11864 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 512x384 [SAR 1:1 DAR 4:3], 30 tbr, 90k tbn, 180k tbc
    Stream #0:1[0x101](jpn): Audio: aac ([15][0][0][0] / 0x000F), 22050 Hz, stereo, fltp, 88 kb/s
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf54.63.104
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 512x384 [SAR 1:1 DAR 4:3], q=2-31, 90k tbn, 90k tbc
    Stream #0:1(jpn): Audio: aac ([64][0][0][0] / 0x0040), 22050 Hz, stereo, 88 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 6852 fps=0.0 q=-1.0 size=   16005kB time=00:03:48.34 bitrate= 574.2kbits/frame=18284 fps=18283 q=-1.0 size=   37212kB time=00:10:09.36 bitrate= 500.3kbitframe=30997 fps=20664 q=-1.0 size=   64882kB time=00:17:13.13 bitrate= 514.5kbitframe=44215 fps=22107 q=-1.0 size=   94363kB time=00:24:33.73 bitrate= 524.5kbitframe=53566 fps=21144 q=-1.0 size=  119825kB time=00:29:45.43 bitrate= 549.8kbitframe=66513 fps=21926 q=-1.0 size=  146324kB time=00:36:57.00 bitrate= 540.7kbitframe=75414 fps=21303 q=-1.0 size=  168300kB time=00:41:53.70 bitrate= 548.5kbitframe=87198 fps=21583 q=-1.0 size=  197198kB time=00:48:26.50 bitrate= 555.8kbitframe=97641 fps=21506 q=-1.0 size=  224716kB time=00:54:14.60 bitrate= 565.6kbitframe=107076 fps=21245 q=-1.0 size=  245085kB time=01:01:30.87 bitrate= 544.0kbiframe=109313 fps=21094 q=-1.0 Lsize=  253887kB time=01:04:00.53 bitrate= 541.6kbits/s    
video:212399kB audio:38223kB subtitle:0 global headers:0kB muxing overhead 1.303254%

Except now, both the audio and the video just stop, while the file keeps on playing. Every bloody time I do the same thing, something different happens...

Tamara Macadam

Posted 2013-08-07T02:35:05.120

Reputation: 63

Please show your ffmpeg command and the complete console output. – llogan – 2013-08-07T17:13:38.460

Why do you use an intermediat transportstream? – Endoro – 2013-08-11T22:49:35.390

@Endoro A what? – Tamara Macadam – 2013-08-11T23:05:46.850

Why do you encode from MP4 to TS (intermediate1.ts)? – Endoro – 2013-08-11T23:22:08.700

It says that it's one way to do it on the FFMPEG wiki. https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files And frankly, I'm just trying every option that there is now.

– Tamara Macadam – 2013-08-11T23:33:10.093

the audio bitrates from part1 (82 kb/s) and part2 (125 kb/s) are too different for concenation. – Endoro – 2013-08-11T23:39:38.260

That's weird, considering the bitrate part under the audio tab in Handbrake was set to 160 both times... – Tamara Macadam – 2013-08-11T23:52:52.060

Answers

2

If you want to concatenate the input files without re-encoding, both files should have the same audio sample rate. The audio sample rate is 22050 Hz in your first file and 44100 Hz in your second file. You will need to re-encode the audio in one of the files in order to match the other one.

mark4o

Posted 2013-08-07T02:35:05.120

Reputation: 4 729

I'm... not sure how I didn't realise this to begin with, but it works now. Oddly it doesn't work in VLC, but I can get it to work in pretty much everything else, so I'm going to put that down to a bug. Thanks! – Tamara Macadam – 2013-08-13T10:18:26.987

0

Use the concat demuxer on this page : https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files

It worked for me ! Hope this helps...

ffmpeg -f concat -i mylist.txt -c copy output

Mylist.txt should have this form :

# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

Nicolas Sursock

Posted 2013-08-07T02:35:05.120

Reputation: 33

Tried it before, didn't work; tried it this time around, still doesn't work. Not only is there no sound from the footage of the second file, but the file claims it is two hours long, despite the fact that the sum of the video time is a little over one hour, thus pretty much breaking it and making it impossible to cut back down to size. – Tamara Macadam – 2013-08-09T12:27:26.070