Gstreamer学习时的相关命令 - guogeWS/tools GitHub Wiki

ubuntu下安装方法及相关组件

sudo apt-get install libgstreamer1.0-0 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

sudo apt-get install libgstreamer1.0-0 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-qt5 gstreamer1.0-pulseaudio

GStreamer源码路径

https://gstreamer.freedesktop.org/data/src/

tee 多分支的使用方法

gst-launch-1.0 -vvv v4l2src device=/dev/video1 ! video/x-h264,framerate=25/1 ,width=1920,height=1080! h264parse ! rtph264pay ! tee name=t ! queue ! udpsink host=192.168.1.5 port=7000 t. ! queue ! udpsink host=192.168.1.5 port=5600
参考连接 https://zcwlwen.github.io/2018/12/14/GStreamer%E4%BD%BF%E7%94%A8tee%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF/

使用技巧

在各类sink输出的时候最好在结尾加入 sync=false,可以有效的减少延时 ,注意在window平台使用CMD调用命令时,命令的单引号改为双引号,如udpsrc

查询已连接的设备

gst-device-monitor-1.0 gst-inspect-1.0 nvcamerasrc

查询可用的输出sink

gst-inspect-1.0 | grep sink

英伟达 jetson nano

h264解码、编码

omxh264enc 使用bitrate=600000设置传输的波特率来调整传输的质量和带宽
omxh264dec
参考文件 :Accelerated_GStreamer_User_Guide.pdf

h265解码、编码

omxh265enc omxh265dec

测试用的sink

  1. ximagesink:使用XWindow输出,基本都支持
  2. xvimagesink:使用XVideo extension输出,在ubuntu下要装一大堆库才支持
  3. sdlvideosink:使用sdl库输出,需要装sdl库
  4. dfbvideosink:用DirectFB库输出,需要apt-get install directfb* 安装后才能使用
  5. cacasink:使用的是libcaca库,是在控制台下用字符加颜色的方式显示图像的,与win32下的 SetConsoleTextAttribute 函数效果差不多,支持X11, S-Lang,ncurses和raw等几种方式输出用ncurse的方式:CACA_DRIVER=ncurses gst-launch filesrc location=test.avi ! decodebin ! ffmpegcolorspace ! cacasink
  6. fpsdisplaysink:能在控制台上打印出当前的和平均的framerate
  7. aasink:用ascii字符的形式在控制台输出图像,与cacasink类似,但是不支持颜色

一些测试命令

gst-launch-1.0 videotestsrc ! x264enc ! rtph264pay ! udpsink host=192.168.1.203 port=5600

gst-launch-1.0 udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' ! rtph264depay ! avdec_h264 ! autovideosink fps-update-interval=1000 sync=false

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,framerate=25/1,width=640,height=480 ! videoconvert ! x264enc ! rtph264pay ! udpsink host=192.168.1.135 port=5600 &

gst-launch-1.0 udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' ! rtph264depay ! avdec_h264 ! videoconvert ! aasink

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2, framerate=30/1, width=320,height=240 ! videoconvert ! jpegenc ! rtpjpegpay ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG' ! rtpjpegdepay ! jpegdec ! videoconvert ! aasink

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=I420, framerate=25/1, width=320,height=240 ! avenc_mjpeg ! rtpjpegpay ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG' ! rtpjpegdepay ! jpegparse ! videoconvert ! aasink

gst-launch-1.0 videotestsrc ! video/x-h264, stream-format=byte-stream,alignment=au ! x264enc ! rtph264pay ! queue ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 videotestsrc ! video/x-raw,format=YUY2,framerate=25/1 ,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 ! rtph264pay ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2,framerate=25/1,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 ! rtph264pay ! udpsink host=192.168.1.135 port=5600

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2, framerate=25/1, width=320,height=240 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=320,height=240 ! jpegenc ! jpegparse ! rtpjpegpay ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-h264,framerate=25/1 ,width=1280,height=720,stream-format=byte-stream,alignment=au ! h264parse ! rtph264pay ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 v4l2src device=/dev/video1 ! videoconvert ! h264parse ! rtph264pay ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-h264,framerate=25/1 ,width=640,height=480! h264parse ! rtph264pay pt=96 ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,framerate=25/1 ,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! jpegenc ! jpegparse ! rtpjpegpay ! udpsink host=192.168.1.201 port=5600

gst-launch-1.0 uvch264src device=/dev/video1 num-buffers=2000 ! rtph264pay ! udpsink host=192.168.1.135 port=5600

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,framerate=25/1 ,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! aasink

gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-h264,framerate=25/1 ,width=640,height=480! h264parse ! avdec_h264 direct-rendering=false lowres=2 ! aasink

gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-h264,framerate=30/1,profile=baseline ! h264parse ! rtph264pay pt=96 ! udpsink host=192.168.1.135 port=5600 async=false

gst-launch-1.0 videotestsrc ! video/x-raw,format=YUY2,framerate=25/1 ,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 ! rtph264pay ! udpsink host=192.168.168.222 port=5600 async=false

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2,framerate=25/1,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 ! rtph264pay ! udpsink host=192.168.168.222 port=5600

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2,framerate=25/1,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 byte-stream=true ! rtph264pay ! udpsink host=192.168.168.223 port=5600

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2,framerate=25/1,width=640,height=480 ! videoconvert !framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 byte-stream=true ! rtph264pay ! udpsink host=192.168.1.223 port=5600

根据网络通信情况执行GStreamer命令的脚本用例

while true ;
do ping -c 2 192.168.168.223 > /dev/null 2>&1 ;
if [ $? -eq 0 ];
then gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2,framerate=25/1,width=640,height=480 ! videoconvert ! video/x-raw,format=I420,framerate=25/1 ,width=640,height=480 ! x264enc speed-preset=1 byte-stream=true ! rtph264pay ! udpsink host=192.168.168.223 port=5600 ;
else echo nononono ;
fi;
sleep 2s ;
done;

OPENCV中使用GStreamer搭建RTSP视频流服务器

1.安装 v4l2loopback,使用命令cv::VideoWriter("appsrc ! videoconvert ! video/x-raw,format=BGRx ! tee ! v4l2sink device=/dev/video1", 0, 30, cv::Size(1280, 720));将opencv中合成的视频输出到虚拟摄像头video1中
2. 安装 test-launch 调用命令./test-launch "v4l2src device=/dev/video1 ! video/x-raw,format=I420,framerate=30/1,width=1280,height=720 ! omxh264enc ! video/x-h264,stream-format=byte-stream,width=1280,height=1280,framerate=30/1 ! rtph264pay name=pay0 pt=96 config-interval=1 ",利用Video1建立RTSP视频流,参考链接https://devtalk.nvidia.com/default/topic/1018689/jetson-tx2/vlc-playing-gstreamer-flow/post/5187270/#5187270
3.参考链接 https://forums.developer.nvidia.com/t/how-to-generate-rtsp-stream-with-gstreamer-in-tx2/75876/3