I'm looking for some universal way to dump rtsp stream. I want to figure out, that some rtsp stream is working well and server is sending some watchable video.
openRTSP
At first, google recommends me openRTSP tool.
openRTSP -4 ${stream_link} > ${output_file}
But output video file dumped by that tool is not really correct. Video decoder (ffdec) returns many errors like "Failed to decode video packet" and "[h264] no frame!", which don't suit me.
ffmpeg
Then I've tried to dump rtsp stream with ffmpeg tool.
ffmpeg -loglevel debug -i "${stream_link}" -s 640x480 -vcodec copy -acodec copy -y ${output_file}
But streaming process was interrupted often by error:
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 730672 >= 730672 av_interleaved_write_frame(): Invalid argument
I'm trying to use --fflags igndts
but ffmpeg doesn't ignore these errors. It doesn't make any sense, because that error actually means that audio and video streams are sending asynchronously. The worst thing is that dumped file, resulted by that interrupted dump, is not correct too. Ffdec return some error:
ERROR [mov,mp4,m4a,3gp,3g2,mj2] moov atom not found ERROR [ffdec] av_open_input_file: Operation not permitted
After a nice cup of googling I've found, that it's really old ffmpeg's muxer bug.
mplayer
Than I've tried to use mplayer with LIVE_555 lib.
mplayer -noframedrop -dumpfile ${output_file} -dumpstream ${stream_link}
But I've got some errors too.
Stream not seekable! Core dumped ;)
Question
I think I'm doing something wrong. It's sounds really ridiculous, that there is no way to save rtsp stream in correct and playable video-file.
Maybe there are some another tools which can help with that task? Actually, I will be grateful for any advice for all kind of libs and languages. But that process should be automatic and have cli.
Refinements
Something about 50% experiments I've done on the localhost with vlc-streamer that emulates rtsp-broadcaster. Here is a manual which I try to follow.
I have really fresh and latest ffmpeg with x264 support, that I've installed by that useful thread.
Setup > Network > RTSPGo to RTSP page. Check RTSP port numbers on camera for dedicated stream. The Default RTSP port number of each camera model can be found in the User Manual. Open VLC player and select “Open Network Stream” from the Media menu.
RTSP stands for Real Time Streaming Protocol. RTSP allows you to pull a live video stream from your camera and view it from different devices and programs. Its primary uses are to pull a video feed from a camera to an NVR, viewing software, or even home automation solutions.
How RTSP works. When a user or application attempts to stream video from a remote source, the client device sends an RTSP request to the server to determine the available options, such as pause, play and record. The server then returns a list of the types of requests it can accept through RTSP.
Did you try vlc to save rtsp stream? It worked for me.I tried with graphical interface though. But it should also work from command line.
ffmpeg is the easiest way to achieve your goal, but here are some important notes:
First, I advise you to get the last version (2.4.x instead of the 1.2.x shipped with Ubuntu). You can get it from https://www.ffmpeg.org/download.html
You will still get the
Application provided invalid, non monotonically increasing dts to muxer in stream 0: 730672 >= 730672 av_interleaved_write_frame(): Invalid argument error
error but you can get rid of it. This is mainly because the FPS (Frames Per Second) are consistently changing on IP cameras depending on the quality of the connection. Here are 2 solutions that worked for me:
Solution 1 = use the use_wallclock_as_timestamps option so your command looks like
ffmpeg -use_wallclock_as_timestamps 1 -i rtsp://myip:554/mpeg4 -c copy myrecord.avi
PROS = low CPU usage + good quality recordings because nothing is transcoded / CONS = slightly big files (~6Mb / minute)
Solution2 = removing the "-acodec copy -vcodec copy" options in your command. The simple command
ffmpeg -i rtsp://myip:554/mpeg4 myrecord.avi
will do the trick. PROS = small files (~1.2Mb / minute) / CONS = high CPU usage (6% on my computer), because I think it is transcoding to the default codecs + bad quality recordings
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With