之前的内容,我们研究了用GStreamer 实现对USB相机的截图、录像、显示等操作,已经后续的压缩,解压缩,硬件加速实现的办法。但是我们在实际使用中,越来越多的前端接入其实是RTSP码流的网络相机偏多,尤其是前端可能使用海康、大华等大厂的网络相机,所以接下来我们主要研究如果实现RTSP网络流相机的接入的一些操作实现。
目录
1、硬件环境说明
参考文章:
【GStreamer 】5-1 gstreamer实现RTSP相机显示_机器人虎哥的博客-CSDN博客
2、RTSP相机链接播放显示
#playbin 插件播放 需要显示器支持
gst-launch-1.0 playbin uri= rtsp://admin:abcd1234@192.168.11.68:554/h264/ch1/main/av_stream
在nomachine 终端执行命令的效果为:
无报错了,屏幕显示内容也一致。
如果想测试自码流,只需要更换后面的URL即可。
#子码流取流:
#playbin 插件播放 需要显示器支持
gst-launch-1.0 playbin uri= rtsp://admin:abcd1234@192.168.11.68:554/h264/ch1/sub/av_stream
3、将RTSP码流转jpg图片保存
保存每一帧照片
#rtspsrc 指定数据来源,类似之前的v4l2 Receive data over the network via RTSP (RFC 2326)
#location 数据来源URL,需要可以使用playbin能播放
#rtph264depay 从RTSP数据流转接成H264 video Extracts H264 video from RTP packets (RFC 3984)
#avdec_h264 H.264解码 不是所有平台都有,先要查一下自己平台是否有这个插件
#h264parse 分析和缓冲H.264数据流 Parses H.264 streams
#videorate 调整帧率,优化视频流 Drops/duplicates/adjusts timestamps on video frames to make a perfect stream
#jpegenc 编码
#multifilesink 保存缓冲数据,按照一个连续命名文件 Write buffers to a sequentially named set of files
gst-launch-1.0 rtspsrc \
location="rtsp://admin:abcd1234@192.168.11.68:554/h264/ch1/main/av_stream" \
! rtph264depay ! h264parse ! avdec_h264 \
! videorate ! jpegenc ! multifilesink location="img_%06.jpg"
执行结果是保存了连续很多图片:
这条命令很适合我们连续采集照片,基本是按照帧率在采集照片。
只保存一帧照片
#rtspsrc 指定数据来源,类似之前的v4l2 Receive data over the network via RTSP (RFC 2326)
#location 数据来源URL,需要可以使用playbin能播放
#rtph264depay 从RTSP数据流转接成H264 video Extracts H264 video from RTP packets (RFC 3984)
#avdec_h264 H.264解码 不是所有平台都有,先要查一下自己平台是否有这个插件
#h264parse 分析和缓冲H.264数据流 Parses H.264 streams
#videorate 调整帧率,优化视频流 Drops/duplicates/adjusts timestamps on video frames to make a perfect stream
#jpegenc 编码
gst-launch-1.0 rtspsrc \
location="rtsp://admin:abcd1234@192.168.11.68:554/h264/ch1/main/av_stream" \
! rtph264depay ! h264parse ! avdec_h264 \
! videorate ! jpegenc ! filesink location=/home/nvidia/GStreamer/rtsp/pic/file_1280_720_img-1.jpg
这条命令需要手动结束,Ctrl+C 实际上这个文件被不断覆盖重新写了,会保留最近的一帧数据。
相关组件查询详情补充说明
rtspsrc
nvidia@nvidia-desktop:~$ gst-inspect-1.0 rtspsrc
Factory Details:
Description Receive data over the network via RTSP (RFC 2326)
Author Wim Taymans <wim@fluendo.com>, Thijs Vermeir <thijs.vermeir@barco.com>, Lutz Mueller
GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstBin
+----GstRTSPSrc
Pad Templates:
SRC template: 'stream_%u'
Availability: Sometimes
Capabilities:
application/x-rtp
application/x-rdt
Element has no clocking capabilities.
URI handling capabilities:
Element can act as source.
Supported URI protocols:
rtsp
rtspu
rtspt
rtsph
rtsp-sdp
rtsps
rtspsu
rtspst
rtspsh
Pads:
none
rtph264depay
nvidia@nvidia-desktop:~$ gst-inspect-1.0 rtph264depay
Factory Details:
Description Extracts H264 video from RTP packets (RFC 3984)
GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstRTPBaseDepayload
+----GstRtpH264Depay
Pad Templates:
SINK template: 'sink'
Availability: Always
Capabilities:
application/x-rtp
media: video
clock-rate: 90000
encoding-name: H264
SRC template: 'src'
Availability: Always
Capabilities:
video/x-h264
stream-format: avc
alignment: au
video/x-h264
stream-format: byte-stream
alignment: { (string)nal, (string)au }
Element has no clocking capabilities.
Element has no URI handling capabilities.
Pads:
SINK: 'sink'
Pad Template: 'sink'
SRC: 'src'
Pad Template: 'src'
h264parse
nvidia@nvidia-desktop:~$ gst-inspect-1.0 h264parse
Factory Details:
Rank primary + 1 (257)
Long-name H.264 parser
Klass Codec/Parser/Converter/Video
Description Parses H.264 streams
Author Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstBaseParse
+----GstH264Parse
Pad Templates:
SINK template: 'sink'
Availability: Always
Capabilities:
video/x-h264
SRC template: 'src'
Availability: Always
Capabilities:
video/x-h264
parsed: true
stream-format: { (string)avc, (string)avc3, (string)byte-stream }
alignment: { (string)au, (string)nal }
Element has no clocking capabilities.
Element has no URI handling capabilities.
Pads:
SINK: 'sink'
Pad Template: 'sink'
SRC: 'src'
Pad Template: 'src'
videorate
nvidia@nvidia-desktop:~$ gst-inspect-1.0 videorate
Factory Details:
Rank none (0)
Long-name Video rate adjuster
Klass Filter/Effect/Video
Description Drops/duplicates/adjusts timestamps on video frames to make a perfect stream
Author Wim Taymans <wim@fluendo.com>
Plugin Details:
Name videorate
Description Adjusts video frames
Filename /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstvideorate.so
Version 1.14.5
License LGPL
Source module gst-plugins-base
Source release date 2019-05-29
Binary package GStreamer Base Plugins (Ubuntu)
Origin URL https://launchpad.net/distros/ubuntu/+source/gst-plugins-base1.0
GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstBaseTransform
+----GstVideoRate
Pad Templates:
SRC template: 'src'
Availability: Always
Capabilities:
video/x-raw(ANY)
video/x-bayer(ANY)
image/jpeg(ANY)
image/png(ANY)
SINK template: 'sink'
Availability: Always
Capabilities:
video/x-raw(ANY)
video/x-bayer(ANY)
image/jpeg(ANY)
image/png(ANY)
Element has no clocking capabilities.
Element has no URI handling capabilities.
Pads:
SINK: 'sink'
Pad Template: 'sink'
SRC: 'src'
Pad Template: 'src'
Element Properties:
multifilesink
nvidia@nvidia-desktop:~$ gst-inspect-1.0 multifilesink
Factory Details:
Rank none (0)
Long-name Multi-File Sink
Klass Sink/File
Description Write buffers to a sequentially named set of files
Author David Schleef <ds@schleef.org>
GObject
+----GInitiallyUnowned
+----GstObject
+----GstElement
+----GstBaseSink
+----GstMultiFileSink
Pad Templates:
SINK template: 'sink'
Availability: Always
Capabilities:
ANY
Element has no clocking capabilities.
Element has no URI handling capabilities.
Pads:
SINK: 'sink'
Pad Template: 'sink'
Element Properties:
如果对你有帮助,给个赞呗!
纠错,疑问,交流: 911946883@qq.com