RTSP (Real Time Streaming Protocol),实时流协议,是一种应用层协议,专为流媒体运用。本文将介绍 GStreamer, VLC, FFmpeg 这几个东西,怎样发送、接纳 RTSP 流。

条件

  • Ubuntu 18.04 LTS (Bionic Beaver)

GSthttps和http的差异reamer

设备:

sudo apt install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plAPPugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1Git.0-gl gstreameFFmpegr1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

检查所有插件:

# conda deactivate
gst-inspeapplect-1.0 -a

播放 ~/Vffmpeg教程ideos/test.mp4 文件:

gstgit教程-launch-1.0 filesrc location=~/Videos/tegit教程st.mp4 ! decodebin ! autovideosink

播放 /dev/video0 webcam:

gsthttp://192.168.1.1登录-launch-1.0 v4l2src device=approach/dev/video0 
! video/x-raw, format=ffmpeg安卓版别下载YUY2, width=640, height=480, framerHTTPate=30/1 
! auapprovetovideosinkhttp://www.baidu.com

/dev/video0 相关信息,可见后文“关于 Webcam”。

GStreamer RTSP Server

编译 test-launch 比如:

sudo apt install libgstreamer1.0-dev libgstropencv库tspserver-1.0
git clone https://github.com/GStreamer/gst-rtsp-server.git
cd gstffmpeg装置-rtsp-server/
git checkout 1.ffmpeg安卓版别下载18
cd examples/
gccOpenCV test-launch.c -o test-launch $(pkg-config --cflags --libs gstreamer-rtsp-server-1.0)

test-launch 发送 RTSP 检验流:giti轮胎

$ ./test-launch "vidhttpclienteotestsrc ! x264enc ! rtph264pay name=pay0 pt=96"
stream ready at rtsp://127.0.0.1:8554ffmpeg教程/test

gst-launch 接纳 RTSP 检验流:

gst-launch-1opencv下载.0 playbin uri=rtsp://127.0.0.1:8554/test

RTSP 流相关东西介绍

发送 RTSP,https和http的差异test-launch

发送 ~/Videos/test.mp4 文件:

./test-launch "filesrc location=/home/john/Videos/test.mp4 ! decodebin ! x264enc ! rtph264pay name=pay0 pt=96"

发送 /dev/video0 webcam:

./test-launch "v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=64https和http的差异0,height=480 ! videoconvert ! xhttp://www.baidu.com264enc ! rtph264pay name=ffmpeg指令pay0 pt=96"

接纳 RTSP,以 gst-launch

gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test
# orffmpeg指令
gshttps和http的差异t-launch-1.0 rtspsrc lffmpeg装置ocation=ffmpeg兼并视频rtsp://1ffmpeg指令27.0.0.1:8554/tFFmpegest ! decodebin ! auhttp协议tovideosink

参看

  • GStreamer

    • Inshttpclienttalling on Linux
    • Command line tools
    • Plugffmpeg兼并视频ins
  • GStreamer RTSP Server
  • Stream webcam with GStreamopencv3和4的差异eapprover (RTSP)
  • x264 [error]: baseline profile doesn’t support 4ffmpeg兼并视频:2:2

VLCgiti轮胎

设备:

sudo snap install vlc
# allow cameopencv装置教程ra permission
snap connect vlc:camera :camera

检查可用模块:

vlc --list

播放 ~/Videos/test.mp4opencv调用摄像头 文件:

vlc file:///home/john/Videos/test.mp4

播放 /dev/video0 wHTTPebcam:

vlc vhttp代理4l2:///dev/video0:chroma=mjpg:width=640:giti轮胎height=480:fpsffmpeg是什么意思=30

发送 RTSP,以 vlc

发送 ~/Videos/test.mp4gitlab 文件github中文官网网页

vlc file:///home/john/Videos/teffmpeg装置st.mp4 
--sout '#transcode{vcodec=approachh264}:rtp{sdp=rtspopencv人脸辨认算法://:8554/test}'

发送 /dev/ffmpeg是什么意思video0 webcam:

vlc vgithub中文官网网页4l2:///dev/opencv装置教程video0:chroma=yuyv:widtgit教程h=640:height=480:fps=30 
--sout '#transcode{vcodec=h264,width=640,height=480}:rtp{sdp=rtsp://:8554/test}'

接纳 RTSP,以 vlc

vlc rtsp://127.0.0.1:8554/test

参看

  • VLC

    • Modules/file
    • Moduleshttp协议/v4l2
    • Streaming HowTo/Advanced Streaming Usingopencv-python the Command Line
    • Streaming HowTo/Commandhttp://www.baidu.com Line Examples
  • Ubuntu 18.04 Webcam streaming problem

FFmpeg

设备:

sudo apOpenCVt install ffmpeg

发送 RTSP,以 ffserver

配备 ffserver.conf

HTTPPort 8091
HTTPBindAddress 0.0.0.0
RTSPPort 1554
MappleaxHTTPConnections 2000
MaxClffmpeg是什么意思ientsapprove 1000
Maxffmpeg耻辱柱事情Bandwidth 1000
CustomLog -
<Stream test.mp4>
File "/home/john/Videos/test.mp4"http代理
Formagitlabt rtp
</Stream>

打开 ffserver:

$ nohup ffserver -fhttpwatch ffserver.conf &
$ tail nohup.out
libavcodec     57.107.100 / 57.1http://www.baidu.com07.100
libavformatFFmpeg    57approach. 83.100 / 57. 8opencv装置教程3.100
libavdevgitlabice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
liHTTPbswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100
Wed Apr 21 11:28:39 2021 Openingit教程g feed file '/home/john/Videos/test.mp4' foffmpeg装置r stream 'test.mp4'
Weappstored Apgiti轮胎是什么品牌r 21 11:28:39 2021 FFserver started.

接纳 RTSPhttp 404,以 ffplay

ffplay rthttpclientsp://127.0.0.1:1554/tgitlabest.mp4

参看

  • FFmpeg

    • ffsopencv物体辨认erver
  • Streaming RTSP with ffmpeg?
  • Run real time streaming with ffserver?HTTP

关于 MeOpenCVdia

$ sudo apt install ffmpeg
$ ffprobe ~/Videosappear/test.mp4
ffprobe version 3.4.8-0ubuntu0.2 Copyright (c) 2007-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuratffmpeg从入门到通晓ion: --prefix=/usr --extra-veropencv-pythonsion=0ubungiteetu0.2 --toolchain=haapplerdengit指令ed --libdir=/usr/lib/x86_http 30264-liapprovenux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresamopencv3和4的差异ple --enable-avisynth --enable-gnutls --enable-lHTTPadspa --enable-libass --enable-libblgit指令uray --enable-liGitbbs2b --enable-libcaca -http://192.168.1.1登录-enable-libcdio --enable-libflite --enable-libfontconfig --enable-liapplicationbfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enablgithube-libopenjpeg --enable-libopenmpt --enable-libopus --enable-http 302libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsshapplication --enable-libtheoraappointment --enable-liOpenCVbtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libgiti轮胎是什么品牌xml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --eopencv是干什么的nable-openal --enable-opengl --enable-sdl2 --enable-libdc13opencv装置教程94 --enable-libdrm --enable-lappearanceibiec61883 --enable-chromahttp 500print --enable-frei0r --enable-libopencv --enappointmentable-libx264 --enable-shared
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.1apple00
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /git指令  2.  9.100
libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/hhttpwatchoFFmpegme/john/Videos/test.mp4':
Metadata:
majffmpeg教程or_brand     : isom
minor_version   : 512
compatible_brandgithub中文官网网页s: isomiso2avc1mp41
encoder         : Lavf58.20.opencv装置教程100
Duration: 00:10:22.04, start: 0.000000, bitrate: 4205 kb/s
Stream #0:0(und):appear Video: h26opencv是干什么的4 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 4204 kb/s, 25 fps, 25 tbr, 1200k tbn, 2400k tbc (defffmpeg教程ault)http 404
Metadata:
handlgit指令er_name    : VideoHandler
  • ffprobe

关于 Webcam

$ sudo apt install v4l-utffmpeg是什么意思ils
$ v4l2-ctl --list-devices
HD Webcam: HgiteeD Webcam (usb-0000:00:14.0-13):
/degithub永久回家地址v/video0
/dev/video1
$ v4l2-ctl -d 0 --list-formats-ext
ioctl: VIappearDIOC_ENUM_FMT
Index       : 0
Type        : Video Capture
Pixel Format: 'MJPG' (compressed)http 404
Name        : Motion-JPEGgit教程
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Intervahttp://www.baidu.coml: Discrete 0.033s (30.000 fps)
Sizeopencv装置教程: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 352x288
Iffmpeg从入门到通晓nterval: Discrete 0.033s (30.000 fps)ffmpeg教程
Size: Discrete 320x2github永久回家地址40
Interval: Discrete 0.033s (30.000 fps)
Sizffmpeg兼并视频e: Discrete 176x144git指令
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 160x120
Interval: Discrete 0.033s (30.000 fps)
Index       : 1
Type        : Video Capturhttp代理e
Pixel Format: 'YUYV'
Name        : YUYV 4:2:2
Siffmpeg兼并视频ze: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Iffmpeg装置nterval: Discrete 0.050s (20.000 fps)
Size: Discrete 1280x720
Inteopencv入门要学多久rval: Discrete 0.1github中文官网网页00s (10.000 fps)
Size: Dgiti轮胎iscrete 640x360
Interval: Discrete 0.033applications (30.000 fps)
Size: Discrete 352x288
Interval: Diappointmentscrete 0.033s (30.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 176x144
Intervalhttp://192.168.1.1登录: Discrete 0.033s (30.000 fps)
Size: Discrete 160xopencv物体辨认120
Interval: Discrete 0.033s (30.000 fps)

GoCoding 个人实践的经历同享,可注重大众号!