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别人。

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
回答: 在ROS中,可以使用rocon_rtsp_camera_relay功能包来订阅摄像头视频流。根据引用\[1\]的描述,使用rocon_rtsp_camera_relay订阅视频流再发布为rostopic的形式可能会有0.3-0.5秒的延迟。你可以在launch文件中指定IP和端口,然后在浏览器中查看指定的URL来查看视频流。引用\[2\]提供了一个示例URL,你可以将其中的/topic=/image_raw替换为你实际使用的视频流话题名称。如果你需要修改默认的rtsp视频流地址,你可以参考引用\[3\]中的示例launch文件,将其中的default值修改为你实际使用的rtsp视频流地址。 #### 引用[.reference_title] - *1* *3* [linux + ros 使用 catkin 从源码编译安装并运行 rocon_rtsp_camera_relay 订阅 rtsp 视频流](https://blog.csdn.net/weixin_43667077/article/details/130748732)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [ROS订阅视频流(获取摄像头视频流)](https://blog.csdn.net/weixin_43856199/article/details/84870645)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

振华OPPO

你的鼓励是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值