2

I know there's a ton of questions on here about video and audio being out of sync when using ffmpeg, however I couldn't find a single one that solved my problem, so I'm hoping you all can help.

I'm concatenating 3 videos together each with it's own audio track.

  • Video 1: Intro Video (MP4 File)
  • Video 2: Main Video (MP4 File)
  • Video 3: Outro Video (MP4 File)

I am using the following code to do the concat:

ffmpeg -i '.$input.' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediate1.'
ffmpeg -i '.$input_second.' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediate2.'
ffmpeg -i '.$input_third.' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediate3.'
ffmpeg -i "concat:'.$intermediate1.'|'.$intermediate2.'|'.$intermediate3.'" -c copy -        bsf:a aac_adtstoasc '.$output.' 2>&1

The issue is that the audio and video are out of sync on the main video.

Here is the output returned from ffmpeg:

ffmpeg version N-59597-g4ced5d7-syslint 
Copyright (c) 2000-2014 the FFmpeg developers
built on Jan 6 2014 06:11:39 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-4)
configuration: --prefix=/usr/local/cpffmpeg --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-decoder=liba52 --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/cpffmpeg/include/ --extra-ldflags=-L/usr/local/cpffmpeg/lib --enable-version3 --extra-version=syslint 
libavutil 52. 62.100 / 52. 62.100
libavcodec 55. 47.100 / 55. 47.100
libavformat 55. 22.102 / 55. 22.102
libavdevice 55. 5.102 / 55. 5.102
libavfilter 4. 0.103 / 4. 0.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpegts, from 'concat:videos/finals/i1_w22861fd697894f2fc6aeb55462f29ff.ts|videos/finals/i2_T22861fd697894f2fc6aeb55462f29ff.ts':
Duration: 00:04:05.08, start: 1.466733, bitrate: 1535 kb/s
Program 1
Metadata: service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 768x432 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101](und): Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 234 kb/s
Output #0, mp4, to 'videos/finals/s22861fd697894f2fc6aeb55462f29ff.mp4':
Metadata: encoder : Lavf55.22.102
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 768x432 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 90k tbn, 90k tbc
Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 234 kb/s
Stream mapping: Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x184b640] Non-monotonous DTS in output stream 0:1; previous: 651264, current: 650250; changing to 651265. This may result in incorrect timestamps in the output file. 
[mp4 @ 0x184b640] Non-monotonous DTS in output stream 0:0; previous: 2444442, current: 2444442; changing to 2444443. This may result in incorrect timestamps in the output file.
[mp4 @ 0x184b640] Non-monotonous DTS in output stream 0:0; previous: 2447445, current: 2447445; changing to 2447446. This may result in incorrect timestamps in the output file.
frame= 7756 fps=0.0 q=-1.0 Lsize= 41685kB time=00:04:18.72 bitrate=1319.9kbits/s" [32]=> string(82) "video:35379kB audio:6137kB subtitle:0 global headers:0kB muxing overhead 0.405115%"

Can anyone help me resolve this or point in the right direction? If you need further information, please let me know.

  • Please show the complete console output of: ffmpeg -i intro.mp4 -i main.mp4 -i outro.mp4 – llogan Jan 6 '14 at 18:36
  • @LordNeckbeard Jeff and I were chatting offline and we dealt with the issue by using the concat filter. I got the non-monotonous DTS errors even when bringing all videos to the same format (codec-wise and dimensions), so it could be a bug. I'll file a report if I can reproduce it. – slhck Jan 6 '14 at 18:44

Your Answer

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

Browse other questions tagged or ask your own question.