Search code examples
linuxgstreamerrtsp

Play rtsp stream from webcam using Gstreamer


I want to stream video from an IP camera TS-WPTCAM. I can directly stream the video in vlc using rtsp://192.168.100.50:19112/ipcam_h264.sdp but when i try with Gstreamer, it does not play the video. Below is the output.

Lnx-Workstation:~$ gst-launch-1.0 -v rtspsrc location="rtsp://192.168.100.50:19112/ipcam_h264.sdp" name=demux demux. ! queue max-size-buffers=2 ! rtph264depay ! autovideosink sync=false

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Got context from element 'autovideosink0': gst.gl.GLDisplay=context, gst.gl.GLDisplay=(GstGLDisplay)"\(GstGLDisplayGBM\)\ gldisplaygbm0";
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.100.50:19112/ipcam_h264.sdp
0:00:20.130738709 13686 0x5632fcf9d2d0 ERROR                default gstrtspconnection.c:1004:gst_rtsp_connection_connect_with_response: failed to connect: Socket I/O timed out
0:00:20.130840128 13686 0x5632fcf9d2d0 ERROR                rtspsrc gstrtspsrc.c:4702:gst_rtsp_conninfo_connect:<demux> Could not connect to server. (Generic error)
0:00:20.130850670 13686 0x5632fcf9d2d0 WARN                 rtspsrc gstrtspsrc.c:7469:gst_rtspsrc_retrieve_sdp:<demux> error: Failed to connect. (Generic error)
0:00:20.130893392 13686 0x5632fcf9d2d0 WARN                 rtspsrc gstrtspsrc.c:7548:gst_rtspsrc_open:<demux> can't get sdp
0:00:20.130917551 13686 0x5632fcf9d2d0 WARN                 rtspsrc gstrtspsrc.c:5628:gst_rtspsrc_loop:<demux> we are not connected
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:demux: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(7469): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstRTSPSrc:demux:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

I also tried to play the video using playbin like this:

Lnx-Workstation:~$ gst-launch-1.0 -v playbin uri=rtsp://192.168.100.50:19112/ipcam_h264.sdp uridecodebin0::source::latency=100

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: ring-buffer-max-size = 0
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: buffer-size = -1
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: buffer-duration = -1
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: use-buffering = false
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: download = false
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: uri = rtsp://192.168.100.50:19112/ipcam_h264.sdp
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: connection-speed = 0
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source: latency = 100
/GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0: source = "\(GstRTSPSrc\)\ source"
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.100.50:19112/ipcam_h264.sdp
0:00:20.040912220 13549 0x55e2654b5e80 ERROR                default gstrtspconnection.c:1004:gst_rtsp_connection_connect_with_response: failed to connect: Socket I/O timed out
0:00:20.041032034 13549 0x55e2654b5e80 ERROR                rtspsrc gstrtspsrc.c:4702:gst_rtsp_conninfo_connect:<source> Could not connect to server. (Generic error)
0:00:20.041058980 13549 0x55e2654b5e80 WARN                 rtspsrc gstrtspsrc.c:7469:gst_rtspsrc_retrieve_sdp:<source> error: Failed to connect. (Generic error)
0:00:20.041160200 13549 0x55e2654b5e80 WARN                 rtspsrc gstrtspsrc.c:7548:gst_rtspsrc_open:<source> can't get sdp
0:00:20.041185827 13549 0x55e2654b5e80 WARN                 rtspsrc gstrtspsrc.c:5628:gst_rtspsrc_loop:<source> we are not connected
ERROR: from element /GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(7469): gst_rtspsrc_retrieve_sdp (): /GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

*** Playbin for a file source works.

How can I play RTSP video using GStreamer?

EDIT: As per Gregory's answer:

Lnx-Workstation:~$ gst-launch-1.0 -v rtspsrc location="rtsp://192.168.100.50:19112/ipcam_h264.sdp" ! queue max-size-buffers=2 ! rtph264depay ! h264parse ! decodebin ! autovideosink sync=false

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Progress: (connect) Connecting to rtsp://192.168.100.50:19112/ipcam_h264.sdp
0:00:20.108314006  3310 0x563cd86e8850 ERROR                default gstrtspconnection.c:1004:gst_rtsp_connection_connect_with_response: failed to connect: Socket I/O timed out
0:00:20.108425505  3310 0x563cd86e8850 ERROR                rtspsrc gstrtspsrc.c:4702:gst_rtsp_conninfo_connect:<rtspsrc0> Could not connect to server. (Generic error)
0:00:20.108449668  3310 0x563cd86e8850 WARN                 rtspsrc gstrtspsrc.c:7469:gst_rtspsrc_retrieve_sdp:<rtspsrc0> error: Failed to connect. (Generic error)
0:00:20.108540016  3310 0x563cd86e8850 WARN                 rtspsrc gstrtspsrc.c:7548:gst_rtspsrc_open:<rtspsrc0> can't get sdp
0:00:20.108569689  3310 0x563cd86e8850 WARN                 rtspsrc gstrtspsrc.c:5628:gst_rtspsrc_loop:<rtspsrc0> we are not connected
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(7469): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
Failed to connect. (Generic error)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

The error seems to be the same.


Solution

  • You are depayloading H264 from RTP, but you forgot to parse and decode it before passing it to autovideosink. I also don't know why you need the demux part, because you use only video and only one stream. Try the following:

    gst-launch-1.0 -v rtspsrc location="rtsp://192.168.100.50:19112/ipcam_h264.sdp" ! queue max-size-buffers=2 ! rtph264depay ! h264parse ! decodebin ! autovideosink sync=false