How to save a RTSP video stream to MP4 file via gstreamer?

Juster picture Juster · Sep 15, 2014 · Viewed 21.7k times · Source

I need to get a video stream from my camera via RTSP and save it to a file. All of this needs to be done via gstreamer.

After some google searching, I tried the following:

gst-launch-1.0 rtspsrc location=rtsp://192.168.1.184/live2.sdp ! queue ! rtph264depay ! avdec_h264 ! mp4mux ! filesink location=result3.mp4

but it gives the error: "Erroneous pipeline: could not link avdec_h264-0 to mp4mux0"

gst-launch-1.0 rtspsrc location=rtsp://192.168.1.184/live2.sdp ! queue ! rtph264depay ! h264parse ! mp4mux ! filesink location=result3.mp4

It starts doing work, but the result file is not playable via VLC.

What is the right command to do? And if you choose between h264parse and avdec_h264, could you please explain why?

Answer

Haris Kovacevic picture Haris Kovacevic · Sep 20, 2014

You need to add -e flag (end of stream) so that mp4mux can finalize file or else you'll get corrupted non playable file.

 gst-launch -e rtspsrc location=url ! decodebin ! x264enc ! mp4mux ! filesink location=file.mp4