ros_rtsp订阅Image类型topic转换为rtsp视频流

在这里插入图片描述

一、安装环境

  • ROS

  • gstreamer development libs,包括base、good、bad和rtspserver:


sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev libgstrtspserver-1.0-dev 

二、在catkin工作空间中构建

导航进入到我们的catkin工作空间下的 src 目录:

cd ~/Demo/rtspServer/src

从仓库克隆软件包

git clone https://github.com/CircusMonkey/ros_rtsp.git

返回工作空间的根目录,编译软件包:

cd ..
catkin_make pkg:=ros_rtsp

在这里插入图片描述

三、设置流

修改config/stream_setup.yaml 来适配需要的流,你可以添加任意数量的流。主要修改的信息为source、framerate、width和height,其中framrate非常重要,10是最佳数字,不要在意你相机的真实fps。

# Set up your streams to rtsp here.
streams: # Cannot rename - must leave this as is.

  # Example v4l2 camera stream
  stream-x:                 # Can name this whatever you choose
    type: cam               # cam - Will not look in ROS for a image. The video src is set in the 'source' parameter.
    codec: cam              # codec - Which codec to encode the stream. Currently support `x264enc` and `nvh264enc`
    source: "v4l2src device=/dev/video0 ! videoconvert ! videoscale ! video/x-raw,framerate=15/1,width=1280,height=720"  # Should work with most valid gstreamer piplines (ending with raw video) 
    mountpoint: /front      # Choose the mountpoint for the rtsp stream. This will be able to be accessed from rtsp://<server_ip>/front
    bitrate: 800            # bitrate for the h264 encoding.

  # Example ROS Image topic stream
  this-is-stream-42:        # Can name this whatever you choose
    type: topic             # topic - Image is sourced from a sensor_msgs::Image topic
    codec: cam              # codec - Which codec to encode the stream. Currently support `x264enc` and `nvh264enc`
    source: /usb_cam0/image_raw  # The ROS topic to subscribe to
    mountpoint: /back      # Choose the mountpoint for the rtsp stream. This will be able to be accessed from rtsp://<server_ip>/back
    caps: video/x-raw,framerate=10/1,width=640,height=480  # Set the caps to be applied after getting the ROS Image and before the x265 encoder.
    bitrate: 500            # bitrate for the h264 encoding.

在这里插入图片描述

四、推出视频流

启动ros核心,再启动launch文件。

roscore
roslaunch ros_rtsp rtsp_streams.launch

五、验证视频流

1、安装vlc拉流

sudo apt-get install vlc

VLC可视化界面打开网络串流即可。

2、安装gstreamer拉流

检测一个流是否工作最好的方式是使用gst-launch-1.0, 你需要在你的客户端系统安装gstreamer,具体查看gstreamer.freedesktop.org

在这里插入图片描述

安装好之后,输入下面命令进行检测:

gst-launch-1.0 -v rtspsrc location=rtsp://<server_ip>:8554/<your_stream_mountpoint> drop-on-latency=true use-pipeline-clock=true do-retransmission=false latency=0 protocols=GST_RTSP_LOWER_TRANS_UDP ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink sync=true

3、安装FFmpeg拉流

ffplay -i rtsp://<server_ip>:8554/<your_stream_mountpoint>

别人是你两倍的工作量,你却花别人两倍的时间做完,你=1/4别人。

猜你喜欢

转载自blog.csdn.net/qq_42257666/article/details/130559000