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

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

After doing some googling, 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 an error: "Error pipeline: failed to bind avdec_h264-0 with mp4mux0"

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

It starts to do the job, but the result file does not play through the VLC.

What team do you need to do? And if you choose between h264parse and avdec_h264, could you explain why?

+6
source share
2 answers

You need to add the -e flag (end of stream) so mp4mux can complete the file, otherwise you will get a corrupted unplayable file.

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

The second command looks right. The h264 raw video data is a bit complicated because it has two characteristics - alignment and stream-format, which can vary. h264parse can convert h264 data to the form needed for various h264-related GStreamer elements.

avdec_h264 - decoder element. You do not want to decode the data, as you apparently do not display it. You put the h264 encoded data from the RTSP stream into the mp4 container file.

If the file does not play, you should make sure that the stream is good or try other media players and see if they work (mplayer, Media Player, Quicktime, whatever).

You can also try muxing into the matroska container file using the "matroskamux" element.

+6
source

Source: https://habr.com/ru/post/975267/


All Articles