[FFmpeg-user] Non-monotonic DTS errors, saving a live encode via mediaMTX

Leo Izen leo.izen at gmail.com
Fri Dec 27 17:34:16 EET 2024


On 12/26/24 8:42 PM, Andrew Strachan wrote:
> Hi,
> 
> I am please looking for some advice. live encoding from a decklink card to MediaMTX (on windows) then using ffmpeg to save the live stream to file. I need to be able to independently stop and start the saving of the file, that's why I am using this setup. We are also going to send the live stream to a CDN, via another instance of ffmpeg.
> 
> Here is my current command to encode;
> 
> ffmpeg.exe -rtbufsize 2G -re -format_code Hp30 -f decklink -i 35:00000000:00230600 -framerate 30 -video_size 1920x1080 -pix_fmt uyvy422 -vcodec libx264 -preset veryfast -x264-params "keyint=120:min-keyint=120:scenecut=0" -tune stillimage -b:v 3000k -minrate 3000k -maxrate 3000k -bufsize 3000k -acodec aac -ac 2 -ar 48000 -b:a 128k -g 120 -f rtsp rtsp://localhost:8554/mystream
> 
> then to save the file I am using this;
> ffmpeg -rtsp_transport tcp -fflags +igndts -copyts -i rtsp://localhost:8554/mystream -start_at_zero -c copy output.ts
> 
> I don't have the time to re-encode the .ts - just we will do a -copy and change to .mp4 which will be the final output.
> 
> I keep getting Non-monotonic DTS errors, which I could just ignore, but I think they are suggesting something is wrong. My test .ts files will play in VLC, but I don't think they are 'good enough'. both seeking and audio sync does not look right.
> 

First of all, -video_size 1920x1080 and -pix_fmt uyvy422 appear to be 
input options, which should go before the -i, so you would end up with 
-f decklink -video_size 1920x1080 -pixel_format uyvy422 -i ....

Likewise, -copyts and -start_at_zero are both input options. However, to 
answer your question, it looks like you have -fflags +igndts, which 
causes the demuxer to ignore the DTS of the input files. DTS is "demux 
time stamp." Sometimes, frames are decoded/demuxed in a different order 
than they are presented - this is the case with B-frames 
(bi-directional), which are frames that include both forward and 
backward predictions.

By setting -fflags +igndts, you're telling FFmpeg to ignore the DTS, and 
it likely is generating fake DTS values based on the PTS, which are 
incorrect. The PTS are out of order, as you would expect when b-frames 
are present, causing the DTS to also be out of order. DTS being out of 
order is not legal (unlike PTS), so the MPEG-TS muxer is observing this, 
fixing it, and throwing a warning.

In order to fix this, you may want to simply remove -fflags +igndts.

As for seeking the output file with VLC, mpegts is not an easily 
seekable format and you should no generally expect that to work well.

- Leo Izen (Traneptora)



More information about the ffmpeg-user mailing list