使用 Gstreamer 从网络摄像头播放 rtsp 流
Play rtsp stream from webcam using Gstreamer
我想从 IP 摄像头流式传输视频 TS-WPTCAM。
我可以使用 rtsp://192.168.100.50:19112/ipcam_h264.sdp
直接在 vlc 中流式传输视频,但是当我尝试使用 Gstreamer 时,它不播放视频。
下面是输出。
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 ...
我也尝试过使用 playbin
播放视频,如下所示:
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 有效。
如何使用 GStreamer 播放 RTSP 视频?
编辑:
根据格雷戈里的回答:
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 ...
错误好像是一样的
您正在 depay
从 RTP
加载 H264
,但您忘记在将其传递给 autovideosink
之前对其进行解析和解码。我也不知道你为什么需要 demux
部分,因为你只使用视频和一个流。
尝试以下操作:
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
不确定您的情况,但 IIRC 如果安装了 plugins-ugly,某些 gstreamer 版本可能会出现 RTSP 身份验证问题。你可以试试:
sudo apt-get remove gstreamer1.0-plugins-ugly
如果不够,您可以分享 sdp 以获得进一步的建议。
我想从 IP 摄像头流式传输视频 TS-WPTCAM。
我可以使用 rtsp://192.168.100.50:19112/ipcam_h264.sdp
直接在 vlc 中流式传输视频,但是当我尝试使用 Gstreamer 时,它不播放视频。
下面是输出。
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 ...
我也尝试过使用 playbin
播放视频,如下所示:
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 有效。
如何使用 GStreamer 播放 RTSP 视频?
编辑: 根据格雷戈里的回答:
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 ...
错误好像是一样的
您正在 depay
从 RTP
加载 H264
,但您忘记在将其传递给 autovideosink
之前对其进行解析和解码。我也不知道你为什么需要 demux
部分,因为你只使用视频和一个流。
尝试以下操作:
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
不确定您的情况,但 IIRC 如果安装了 plugins-ugly,某些 gstreamer 版本可能会出现 RTSP 身份验证问题。你可以试试:
sudo apt-get remove gstreamer1.0-plugins-ugly
如果不够,您可以分享 sdp 以获得进一步的建议。