文章目录
- 一、安装环境
- 二、在catkin工作空间中构建
- 三、设置流
- 四、推出视频流
- 五、验证视频流
- 1、安装vlc拉流
- 2、安装gstreamer拉流
- 3、安装FFmpeg拉流
一、安装环境
-
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 streamstream-x: # Can name this whatever you choosetype: 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>/frontbitrate: 800 # bitrate for the h264 encoding.# Example ROS Image topic streamthis-is-stream-42: # Can name this whatever you choosetype: topic # topic - Image is sourced from a sensor_msgs::Image topiccodec: cam # codec - Which codec to encode the stream. Currently support `x264enc` and `nvh264enc`source: /usb_cam0/image_raw # The ROS topic to subscribe tomountpoint: /back # Choose the mountpoint for the rtsp stream. This will be able to be accessed from rtsp://<server_ip>/backcaps: 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别人。