基于gstreamer的rtsp推流 (USB摄像头)

一. 配置gstreamer环境

参考上篇文章 :ubuntu16.04上安装gstreamer

二. 安装gstreamer-rtsp-server

git clone  -b 1.8 https://github.com/GStreamer/gst-rtsp-server.git  //下载源码
cd gst-rtsp-server      
./autogen.sh
sudo make
sudo make install

三、读取usb摄像头并推rtsp流 

1.  测试

(1) 切换到examples目录:cd examples

(2) 编译   

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

(3) 搭建Rtsp Server:./test-launch "( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )"
(4) 播放rtsp流:gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test
基于gstreamer的rtsp推流 (USB摄像头)_第1张图片

2. usb相机

(1) 切换到examples目录:cd examples

(2) 编译   

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

(3) 搭建Rtsp Server:

./test --gst-debug-level=3 "( v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=2592, height=600, framerate=30/1 ! queue ! x264enc bitrate=10240 !  rtph264pay name=pay0 pt=96 )"
(4) 播放rtsp流:gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test

或者  gst-launch-1.0 playbin uri= rtsp://127.0.0.1:8554/test uridecodebin0::source::latency=0

3. gstreamer的常用命令

// usb 相机


gst-launch-1.0 v4l2src ! autovideosink


gst-launch-1.0 v4l2src device=/dev/video0 ! autovideosink


gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=720, height=720 ! autovideosink -v

gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=720, height=720 !  xvimagesink -ev


// home/zhy/Downloads/soft/GStreamer/gst-rtsp-server-1.16.0/examples

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

推流
 ./test "( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )"

// rtsp推流

./test --gst-debug-level=3 "( v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=2592, height=600, framerate=30/1 ! queue ! x264enc bitrate=10240 !  rtph264pay name=pay0 pt=96 )"


// rtsp 拉流

gst-launch-1.0 playbin uri= rtsp://127.0.0.1:8554/test uridecodebin0::source::latency=0


// rtsp推流加入时间
./test "( 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 )" 

你可能感兴趣的:(Gstreamer,rtsp,linux)