当前位置:   article > 正文

Ubuntu使用USB相机开放RTSP流(gst-rtsp-server-1.16)(一)_ubuntu的v4l2摄像头实时转为rtsp

ubuntu的v4l2摄像头实时转为rtsp

部分内容来自:

https://blog.csdn.net/cau_weiyuhu/article/details/128291577

https://huaweicloud.csdn.net/635642c3d3efff3090b5c9fc.html

        看到这几篇文章,正好现在有USB相机,打算自己尝试一下,但是发现没那么简单,首先就是他们都是使用了老版的 1.8版本,那么我想使用1.16版本的尝试,刚开始失败了,于是自己摸索了一下,最终实验成功,并且发现了一些延时相关的内容。

一、安装环境

       gstreamer和使用USB相机那些内容参考前文。

       从https://github.com/GStreamer/gst-rtsp-server/ 下载一个版本 ,例如参考文章的1.8,我下载的是较新版本的1.16。记得下载源码压缩包,比如我 gst-rtsp-server-1.16.0.tar.xz

        需要安装更高的cmake,这个自己百度源码安装,很简单。

        安装相关库,命令: sudo apt install gtk-doc-tools 

二、编译gst-rtsp-server

  • 下载好gst-rtsp-server以后,解压以后:

        cd gst-rtsp-server-1.16.0

        ./autogen.sh

        sudo make

        sudo make install

  • 在 examples 文件夹里面,可以看到编译好的二进制文件。
  • 如果想自己编译也可以:如果是1.16,那么就无需这一步了

        gcc test-launch.c -o test-launch $(pkg-config --cflags --libs gstreamer-rtsp-server-1.0 gstreamer-1.0)

三、测试编译好的是否正确

  • 测试 test-launch,开放RTSP流

        ./test-launch "( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )"

  • 使用 VLC 或者 gstreamer命令播放 rtsp://127.0.0.1:8554/test

四、测试将USB相机使用RTSP流播放

  • 使用命令开放视频流
./test-launch --gst-debug-level=3 "( v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=640, height=480, framerate=30/1 ! queue ! x264enc bitrate=10240 ! rtph264pay name=pay0 pt=96 )" 

使用VLC播放,或者使用gstreamer播放, gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test

测试发现,有3秒的延迟:

  • 加入时间戳,把分辨率改了:
./test-launch "( v4l2src device=/dev/video0 !  videoconvert! videoscale ! video/x-raw, width=2592, height=600, framerate=30/1 ! timeoverlay ! tee name=vsrc vsrc. ! queue ! videoconvert ! ximagesink vsrc. ! queue ! x264enc tune=zerolatency ! rtph264pay name=pay0 pt=96 )"

        发现延迟少了很多,大概只有1秒。

  • 最终测试出来,是因为x264enc后面加了 bitrate=10240,才会如此的慢,适当调大会好一些,或者把这个参数给去掉,系统会自动设置比特率,这样就快了很多。

./test-launch  "( v4l2src device=/dev/video0 !  videoconvert! videoscale ! video/x-raw, framerate=30/1 ! timeoverlay ! tee name=vsrc vsrc. ! queue ! videoconvert ! ximagesink vsrc. ! queue ! x264enc tune=zerolatency ! rtph264pay name=pay0 pt=96 )"

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/611158
推荐阅读
相关标签
  

闽ICP备14008679号