Ffmpeg concat poduces DTS error errors

I follow the documentation on how to merge files using ffmpeg, but in the process I see a lot of warnings, and the video output stops after the first chunk, but the sound continues to play.

This is the command I use to combine files:

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

These are the warnings I see:

 [concat @ 0x7fee11822a00] DTS 0 < 2500 out of order [webm @ 0x7fee11011000] Non-monotonous DTS in output stream 0:0; previous: 2500, current: 0; changing to 2500. This may result in incorrect timestamps in the output file. 

Video files come from an external source. My current solution is to transcode each file individually into mp4 and then merge them together and then transcode the entire file back to webm. This, of course, it takes some considerable time, but I can not find another solution.

+8
source share
5 answers

Your problems are caused by the -c copy copy argument. As the name of the argument implies, it copies the source encoding. Since each file has different timestamps, potentially starting from scratch, you will receive many warnings. Concat demuxer also requires the same codecs in the input files, so make sure they don't mix.

The solution is to re-encode, specifying the codecs you want to use for your output, for example. -c:v libvpx-vp9 -c:a libopus .

+6
source

After several days of investigation, I found that the videos have the same fps that will solve this problem.

If a.mp4 and b.mp4 have different fps, update them with 30 (regular) fps

 ffmpeg -i a.mp4 -vcodec mpeg4 -vf fps=30 a.output.mp4 ffmpeg -i b.mp4 -vcodec mpeg4 -vf fps=30 b.output.mp4 

Record video tracks in one file

 echo "file a.output.mp4" > videos.txt; echo "file b.output.mp4" > videos.txt; 

Contact

 ffmpeg -f concat -i videos.txt -c copy final.mp4 
+3
source

I fixed my problem not using ffmpeg, but mkvtoolnix using the mkvmerge command.

+2
source

The following is a method for resolving the "DTS out of order" error when concatenating a group of mp4 video files. It also avoids re-encoding.

Although you, as a rule, still see the β€œout of order” error message reported in the console window during processing, concatenation will nevertheless be successful (and without losing synchronization).

Run this code in a batch file. I wrote it on a machine running Windows 7.

 :: *** Concatenate .MP4 files : Stream Copy *** :: You can't concatenate .mp4 files. You have to convert them to an :: intermediate format that can be concatenated, such as .mpg: :: :: 1. Convert the .mp4 videos to .mpg, using ffmpeg. :: 2. Then run a file level concatenation command on :: the .mpg files, to create a combined .mpg file. :: 3. Convert the concatenated .mpg file to .mp4, :: using ffmpeg. :: If the mp4 files contain a h264 stream, use the .TS format (MPEG-TS) :: as the intermediate format (instead of .MPG) :: Convert the .MP4 files to intermediate .TS ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input1.ts ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input2.ts ffmpeg -i input3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input3.ts ffmpeg -i input4.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input4.ts ffmpeg -i input5.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts input5.ts :: MP4 Options SET options=-bsf:a aac_adtstoasc -movflags faststart :: Concatenate the TS files & Convert the output back to MP4 ffmpeg -i "concat:input1.ts|input2.ts|input3.ts|input4.ts|input5.ts" -c copy -video_track_timescale 25 %options% -f mp4 -threads 1 output.mp4 :: Report echo. & ffmpeg -i input1.mp4 -f nul echo. & ffmpeg -i input1.ts -f nul echo. & ffmpeg -i output.mp4 -f nul 
+1
source

All videos for concatenating FFMPEG must have the appropriate encoding, frame rate, etc., otherwise you will get unexpected results. I think it's hard to do without transcoding if your videos come from different sources. I had to look for a lot of solutions from which I could suggest converting your videos to the same intermediate format, and then run the concat command.

Although this approach works, it does not explain what is going wrong. Jan comment comments on this .

First, check your input files with ffprobe: ffprobe video1.mp4

You will get such results.

video1.mp4:

 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1556 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default) 

video2.mp4:

 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 6454 kb/s, 24 fps, 24 tbr, 90k tbn, 48 tbc (default) 

Despite the fact that my FPS and other parameters were the same, I got a 58-second video with 3.1 frames / s instead of the expected 8-second / 24-frame video. An important parameter here is the tbn time base , which is 12288 tbn versus 90k tbn . Concatenation does not recode the input video, only the time base from the first input video is used, which spoils all subsequent videos.

Change the temporary base for the first file:

 ffmpeg -i video1.mp4 -video_track_timescale 90000 video1_fixed.mp4 

Now concatenation gives the correct result:

 ( echo file 'video2.mp4' & echo file 'video1_fixed.mp4' ) | ffmpeg -y -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -c copy output.mp4 
0
source

All Articles