Fix "Non-monotonous DTS" errors in ffmpeg?

Joined
Jun 18, 2018
Messages
5
Reaction score
0
Location
Earth
I'm trying to grab the live RTSP stream from my DS-2CD2085FWD-I camera and stream it in the browser, to do that I need to change it to the HLS format, but when I do that I get a bunch of DTS errors.

The command I use:
ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -thread_queue_size 512 -i "rtsp://admin:123@192.168.1.23:554/Streaming/Channels/3" -codec:v copy -hls_wrap 3600 -hls_playlist_type event ./720p.m3u8

The errors:
[hls @ 0x15bed20] Non-monotonous DTS in output stream 0:0; previous: 0, current: -22500; changing to 1. This may result in incorrect timestamps in the output file.

[hls @ 0x15bed20] Non-monotonous DTS in output stream 0:0; previous: 1, current: -18000; changing to 2. This may result in incorrect timestamps in the output file.

[hls @ 0x15bed20] Non-monotonous DTS in output stream 0:0; previous: 2, current: -13500; changing to 3. This may result in incorrect timestamps in the output file.

[hls @ 0x15bed20] Non-monotonous DTS in output stream 0:0; previous: 3, current: -9000; changing to 4. This may result in incorrect timestamps in the output file.

[hls @ 0x15bed20] Non-monotonous DTS in output stream 0:0; previous: 4, current: -4500; changing to 5. This may result in incorrect timestamps in the output file.

[hls @ 0x15bed20] Non-monotonous DTS in output stream 0:0; previous: 5, current: 0; changing to 6. This may result in incorrect timestamps in the output file.

After a while I'll get a ffmpeg error "muxing overhead: unknown" and it'll stop.

[hls @ 0x18eebe0] Opening './720p.m3u8.tmp' for writingx
frame=1122063 fps= 20 q=-1.0 Lsize=N/A time=15:35:23.39 bitrate=N/A speed= 1x
video:16776652kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Now I can "fix" both the DTS and muxing errors by adding in "-use_wallclock_as_timestamps 1", but now the video will pause for a second every second or so. (each time a new segment is made)

Anyone know a way to fix this?
 
Joined
Jun 18, 2018
Messages
5
Reaction score
0
Location
Earth
Nevermind, here's what I ended up doing if anyone else has these issues.

After trying many different options with ffmpeg (even trying the latest ffmpeg v4) I couldn't get it to work reliably. I ended up giving gstreamer a try, after a bit of googling and trail and error I found the parameters needed and it WORKS!
No DTS errors, no "muxing overhead" issues, it just does what I ask, no errors and doesn't randomly crash half way the night.

I've been testing the following command for over 8 hours and the video isn't way behind, or glitchy/pausing, or playing slow/fast, it's just perfect.

gst-launch-1.0 rtspsrc location=rtsp://admin:myrealpass@192.168.1.23:554/Streaming/Channels/3 ! queue ! rtph264depay ! h264parse ! mpegtsmux ! hlssink target-duration=2 playlist-length=4000 max-files=4000 playlist-location="./stream0.m3u8" location="./fragment%05d.ts"

I'll admit, gstreamer has a bit of a learning curve compared to ffmpeg, but it works, and that's all the matters at the end of the day.
 
Last edited:
Joined
Jun 30, 2018
Messages
1
Reaction score
1
Location
Saint-Petersburg, Russia
You should add -copytb 1 key to output. If you read the documentation carefully, you would find -copytb mode key near -copyts (http://ffmpeg.org/ffmpeg-all.html#Advanced-options).
Mode 1 Use the demuxer timebase.
The time base is copied to the output encoder from the corresponding input demuxer. This is sometimes required to avoid non monotonically increasing timestamps when copying video streams with variable frame rate.
I'm using this setup
Code:
...
FFMPEG_INPUT="-re -f lavfi -i anullsrc -thread_queue_size 2048 -re -r 20 -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i ${RTSP_URL}"
FFMPEG_OUTPUT="-c:v copy -c:a aac -r 20 -copytb 1 -f flv -strict experimental ${YOUTUBE_URL}/${YOUTUBE_KEY}"

COMMAND="ffmpeg -hide_banner -nostdin -nostats -xerror ${FFMPEG_INPUT} ${FFMPEG_OUTPUT}"
...
My bash script is being watched by supervisor (Supervisor: A Process Control System — Supervisor 3.3.4 documentation), and with xerror key it will stop and exit on every error and will restart immediately.
 
Last edited:
Joined
Jun 18, 2018
Messages
5
Reaction score
0
Location
Earth
Thanks Aziz, I gave the `-copytb 1` a try, but a few hours later I still got the "muxing overhead: unknown" error. So I've switched back to gstreamer, as that's been running fine since I switched to it without any errors.

But thanks for the supervisor tip! Will still use that in case one day the stream does error out for some reason.
 

astral

n3wb
Joined
Dec 11, 2017
Messages
8
Reaction score
1
Nevermind, here's what I ended up doing if anyone else has these issues.
After trying many different options with ffmpeg (even trying the latest ffmpeg v4) I couldn't get it to work reliably. I ended up giving gstreamer a try, after a bit of googling and trail and error I found the parameters needed and it WORKS!
No DTS errors, no "muxing overhead" issues, it just does what I ask, no errors and doesn't randomly crash half way the night.
Does your original RTSP stream have audio? If yes, can you hear it in the resulted HLS stream?
 
Joined
Jun 18, 2018
Messages
5
Reaction score
0
Location
Earth
My cam doesn't do audio, so no, I hear no audio.
Also I've gone back to ffmpeg, as the recorded stream from gst would get jumpy whenever the cam would detect movement and send me alerts. ffmpeg seems to handle this better and only produce a tiny stutter in the recorded file, hardly noticeable.

I'm just going to auto restart the recording when it crashes.
 

astral

n3wb
Joined
Dec 11, 2017
Messages
8
Reaction score
1
I see. The thing is that I am facing the same issue with Non-monotonous DTS errors and GStreamer does work better for me as well but my camera also records audio and GStreamer seems to have problem transcoding it into a correct format for the HLS stream to support it. Can you share your current ffmpeg command?
 
Joined
Jun 18, 2018
Messages
5
Reaction score
0
Location
Earth
I use
ffmpeg -hide_banner -rtsp_transport tcp -use_wallclock_as_timestamps 1 -thread_queue_size 512 -i "rtsp://user:mypass@192.168.1.12:554/" -c copy cam_recording.mp4

Though I'm guessing you want to know the HLS command, for that I use:
ffmpeg -hide_banner -rtsp_transport tcp -use_wallclock_as_timestamps 1 -i "rtsp://user:mypass@192.168.1.12:554/Streaming/Channels/3" -c copy -hls_wrap 3600 -hls_playlist_type event /home/pi/hls_live/video/720p.m3u8


Also for gst I ended up using this to record mp4, which works really well, until my cam sends alerts out (setup for 4k 20fps footage).
gst-launch-1.0 -e rtspsrc location="rtsp://user:mypass@192.168.1.12:554/" ! rtpjitterbuffer ! rtph264depay ! capsfilter caps="video/x-h264,width=3840,height=2160,framerate=20/1" ! mp4mux ! filesink location="/home/pi/5tb/thu.mp4"


I also got it working for YouTube (which requires audio), so I added a silent track of audio.
I used channel 3 from my cam, as thats the 720p feed for me.
gst-launch-1.0 -e rtspsrc location="rtsp://user:mypass@192.168.1.12:554/Streaming/Channels/3" ! rtph264depay ! h264parse ! mux. audiotestsrc wave=silence freq=200 ! voaacenc bitrate=16000 ! aacparse ! mux. flvmux streamable=true name=mux ! rtmpsink location="rtmp://a.rtmp.youtube.com/live2/youtubelive-code-goes-here"

I don't know the command, but you should be able to use gst to transcode whatever your audio format is now to something your browser or whatever can decode.​
 
Last edited:

astral

n3wb
Joined
Dec 11, 2017
Messages
8
Reaction score
1
Thank you for the thorough explanation. I also hope to find the right transcoder for gst. But for now I too prefer the ffmpeg + restart on error route.
 
Top