5
votes

I have been trying to concatenate a number of MP4 clips (h264,aac) using the FFMPEG concat protocol documented here. The clips concatenate successfully, however there are multiple errors in the logs including:

  • Non-monotonous DTS in output stream
  • Past duration too large

Additionally, it seems that the audio and video go slightly out of sync as more clips are added - though it is more noticeable on certain players (Quicktime & Chrome HTML5).

Here is the code I am using, any tips would be appreciated!

Convert each video to temp file

ffmpeg -y -i <input file> -vcodec libx264 -acodec aac -f mpegts -bsf:v h264_mp4toannexb -mpegts_copyts 1 <temp file>

Concat temp files

ffmpeg -i concat <input1|input2 ...> -map 0 -vcodec copy -aprofile aac_low -acodec aac -strict experimental -cutoff 15000 -vbsf aac_adtstoasc -b:a 32k <output file>

1
I'm having a similar issue, concating the two videos causes audio issues as well as playback issues, did you ever find a solution? (answer from mulvya below didn't work for me). For me the audio quality becomes really terrible, and the second video plays back at around 0.5 speed compared with the original and the total video length is longer than expected.Dsyko

1 Answers

0
votes

Since you're encoding both audio and video, just use the concat demuxer:

Create a text file with the list of files to be joined

file 'input1'
file 'input2'
file 'input3'
...

Then run

ffmpeg -f concat -i textfile -map 0 \
-vcodec libx264 \
-aprofile aac_low -acodec aac -strict experimental -cutoff 15000 -b:a 32k <output file>