最近在研究如何将Linux中的视频数据推送到流媒体服务器,看到gstreamer还比较不错,于是试了一下
服务端用的SRS,RTMP推流,搭建非常简单,教程可参考:https://blog.csdn.net/qq_52514123/article/details/124845005

中间经历了各种报错吗,我放出来供后人参考
无法打开流的错误:

RROR: from element /GstPipeline:pipeline0/GstRTMPSink:rtmpsink0: Could not open resource for writing.
Additional debug info:
gstrtmpsink.c(293): gst_rtmp_sink_render (): /GstPipeline:pipeline0/GstRTMPSink:rtmpsink0:
Could not connect to RTMP stream “rtmp://192.168.1.146:1935/live1?key=12345 live=1” for writing
Execution ended after 0:00:10.850932699

未知原因报错:

ERROR: from element /GstPipeline:pipeline0/GstRTMPSink:rtmpsink0: Could not open resource for writing.
Additional debug info:
gstrtmpsink.c(293): gst_rtmp_sink_render (): /GstPipeline:pipeline0/GstRTMPSink:rtmpsink0:
Could not connect to RTMP stream “rtmp://192.168.1.146/live1” for writing
EOS on shutdown enabled – waiting for EOS after Error
Waiting for EOS…
ERROR: from element /GstPipeline:pipeline0/GstQueue:queue1: Internal data stream error.
Additional debug info:
gstqueue.c(988): gst_queue_handle_sink_event (): /GstPipeline:pipeline0/GstQueue:queue1:
streaming stopped, reason error (-5)

也是不知道啥错:

Additional debug info: gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: streaming stopped, reason not-negotiated (-4) ERROR: pipeline doesn’t want to preroll.

协商报错:

ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3072): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn’t want to preroll.

下面开始教程

  1. 首先输入lsusb指令查看是否检测到摄像头,最好用cheese查看一下能否显示画面

在这里插入图片描述

1. 安装Gstreamer
这一步很简单,更新软件包后输入命令安装:
Install GStreamer on Ubuntu or Debian
Run the following command:

apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

具体见:gstreamer官网文档

2.通过gst-launch-1.0 推流

gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw, format=YUY2, width=640, height=480, framerate=30/1 ! videoconvert ! x264enc tune=zerolatency ! flvmux streamable=true ! rtmpsink location='rtmp://SRS服务器IP地址:1935/live/stream_name'

其中,/dev/video0 是摄像头设备文件的路径,YUY2 是摄像头输出数据的格式,640x480 是摄像头输出数据的分辨率,30/1 是摄像头输出数据的帧率,stream_name 是你要推流的流名称。记得改服务器地址

执行后,显示如下,没有报错即为成功:
在这里插入图片描述

3.在SRS服务端查看
回到SRS控制界面,发现有新的流

点击预览,看到画面推流成功
在这里插入图片描述

Logo

更多推荐