有趣生活

当前位置:首页>科技>rtsp获取方法流相关工具介绍

rtsp获取方法流相关工具介绍

发布时间:2026-07-25阅读(0)

导读RTSP(RealTimeStreamingProtocol),实时流协议,是一种应用层协议,专为流媒体使用。本文将介绍GStreamer,VLC,FFmp....

RTSP (Real Time Streaming Protocol),实时流协议,是一种应用层协议,专为流媒体使用。本文将介绍 GStreamer, VLC, FFmpeg 这几个工具,如何发送、接收 rtsp 流。

前提
  • Ubuntu 18.04 LTS (Bionic Beaver)[1]
GStreamer

安装:

sudoaptinstalllibgstreamer1.0-0gstreamer1.0-plugins-basegstreamer1.0-plugins-goodgstreamer1.0-plugins-badgstreamer1.0-plugins-uglygstreamer1.0-libavgstreamer1.0-docgstreamer1.0-toolsgstreamer1.0-xgstreamer1.0-alsagstreamer1.0-glgstreamer1.0-gtk3gstreamer1.0-qt5gstreamer1.0-pulseaudio

查看所有插件:

#condadeactivategst-inspect-1.0-a

播放 ~/Videos/test.mp4 文件:

gst-launch-1.0filesrclocation=~/Videos/test.mp4!decodebin!autovideosink

播放 /dev/video0 Webcam:

gst-launch-1.0v4l2srcdevice=/dev/video0\!video/x-raw,format=YUY2,width=640,height=480,framerate=30/1\!autovideosink

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

GStreamer RTSP Server

编译 test-launch 例子:

sudoaptinstalllibgstreamer1.0-devlibgstrtspserver-1.0gitclonehttps://github.com/GStreamer/gst-rtsp-server.gitcdgst-rtsp-server/gitcheckout1.18cdexamples/gcctest-launch.c-otest-launch$(pkg-config--cflags--libsgstreamer-rtsp-server-1.0)

用 test-launch 发送 RTSP 测试流:

$./test-launch"videotestsrc!x264enc!rtph264payname=pay0pt=96"streamreadyatrtsp://127.0.0.1:8554/test

用 gst-launch 接收 RTSP 测试流:

gst-launch-1.0playbinuri=rtsp://127.0.0.1:8554/test

发送 RTSP,以 test-launch

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

./test-launch"filesrclocation=/home/john/Videos/test.mp4!decodebin!x264enc!rtph264payname=pay0pt=96"

发送 /dev/video0 webcam:

./test-launch"v4l2srcdevice=/dev/video0!video/x-raw,format=YUY2,width=640,height=480!videoconvert!x264enc!rtph264payname=pay0pt=96"

接收 RTSP,以 gst-launch

gst-launch-1.0playbinuri=rtsp://127.0.0.1:8554/test#orgst-launch-1.0rtspsrclocation=rtsp://127.0.0.1:8554/test!decodebin!autovideosink

参考
  • GStreamer[2]
  • - Installing on Linux[3]
  • - Command line tools[4]
  • - Plugins[5]
  • GStreamer RTSP Server[6]
  • Stream webcam with GStreamer (RTSP)[7]
  • x264 [error]: baseline profile doesnt support 4:2:2[8]
VLC

安装:

sudosnapinstallvlc#allowcamerapermissionsnapconnectvlc:camera:camera

查看可用模块:

vlc--list

播放 ~/Videos/test.mp4 文件:

vlcfile:///home/john/Videos/test.mp4

播放 /dev/video0 webcam:

vlcv4l2:///dev/video0:chroma=mjpg:width=640:height=480:fps=30

发送 RTSP,以 vlc

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

vlcfile:///home/john/Videos/test.mp4\--sout#transcode{vcodec=h264}:rtp{sdp=rtsp://:8554/test}

发送 /dev/video0 webcam:

vlcv4l2:///dev/video0:chroma=yuyv:width=640:height=480:fps=30\--sout#transcode{vcodec=h264,width=640,height=480}:rtp{sdp=rtsp://:8554/test}

接收 RTSP,以 vlc

vlcrtsp://127.0.0.1:8554/test

参考
  • VLC[9]
  • - Modules/file[10]
  • - Modules/v4l2[11]
  • - Streaming HowTo/Advanced Streaming Using the Command Line[12]
  • - Streaming HowTo/Command Line Examples[13]
  • Ubuntu 18.04 Webcam streaming problem[14]
FFmpeg

安装:

sudoaptinstallffmpeg

发送 RTSP,以 ffserver

配置 ffserver.conf:

HTTPPort 8091HTTPBindAddress 0.0.0.0RTSPPort 1554MaxHTTPConnections 2000MaxClients 1000MaxBandwidth 1000CustomLog -<Stream test.mp4> File "/home/john/Videos/test.mp4" Format rtp</Stream>

开启 ffserver:

$nohupffserver-fffserver.conf&$tailnohup.outlibavcodec57.107.100/57.107.100libavformat57.83.100/57.83.100libavdevice57.10.100/57.10.100libavfilter6.107.100/6.107.100libavresample3.7.0/3.7.0libswscale4.8.100/4.8.100libswresample2.9.100/2.9.100libpostproc54.7.100/54.7.100WedApr2111:28:392021Openingfeedfile/home/john/Videos/test.mp4forstreamtest.mp4WedApr2111:28:392021FFserverstarted.

接收 RTSP,以 ffplay

ffplayrtsp://127.0.0.1:1554/test.mp4

参考
  • FFmpeg[15]
  • - ffserver[16]
  • Streaming RTSP with ffmpeg?[17]
  • Run real time streaming with ffserver?[18]
关于 Media

$sudoaptinstallffmpeg$ffprobe~/Videos/test.mp4ffprobeversion3.4.8-0ubuntu0.2Copyright(c)2007-2020theFFmpegdevelopersbuiltwithgcc7(Ubuntu7.5.0-3ubuntu1~18.04)configuration:--prefix=/usr--extra-version=0ubuntu0.2--toolchain=hardened--libdir=/usr/lib/x86_64-linux-gnu--incdir=/usr/include/x86_64-linux-gnu--enable-gpl--disable-stripping--enable-avresample--enable-avisynth--enable-gnutls--enable-ladspa--enable-libass--enable-libbluray--enable-libbs2b--enable-libcaca--enable-libcdio--enable-libflite--enable-libfontconfig--enable-libfreetype--enable-libfribidi--enable-libgme--enable-libgsm--enable-libmp3lame--enable-libmysofa--enable-libopenjpeg--enable-libopenmpt--enable-libopus--enable-libpulse--enable-librubberband--enable-librsvg--enable-libshine--enable-libsnappy--enable-libsoxr--enable-libspeex--enable-libssh--enable-libtheora--enable-libtwolame--enable-libvorbis--enable-libvpx--enable-libwavpack--enable-libwebp--enable-libx265--enable-libxml2--enable-libxvid--enable-libzmq--enable-libzvbi--enable-omx--enable-openal--enable-opengl--enable-sdl2--enable-libdc1394--enable-libdrm--enable-libiec61883--enable-chromaprint--enable-frei0r--enable-libopencv--enable-libx264--enable-sharedlibavutil55.78.100/55.78.100libavcodec57.107.100/57.107.100libavformat57.83.100/57.83.100libavdevice57.10.100/57.10.100libavfilter6.107.100/6.107.100libavresample3.7.0/3.7.0libswscale4.8.100/4.8.100libswresample2.9.100/2.9.100libpostproc54.7.100/54.7.100Input#0,mov,mp4,m4a,3gp,3g2,mj2,from/home/john/Videos/test.mp4:Metadata:major_brand:isomminor_version:512compatible_brands:isomiso2avc1mp41encoder:Lavf58.20.100Duration:00:10:22.04,start:0.000000,bitrate:4205kb/sStream#0:0(und):Video:h264(Main)(avc1/0x31637661),yuv420p,1920x1080,4204kb/s,25fps,25tbr,1200ktbn,2400ktbc(default)Metadata:handler_name:VideoHandler

关于 Webcam

$sudoaptinstallv4l-utils$v4l2-ctl--list-devicesHDWebcam:HDWebcam(usb-0000:00:14.0-13):/dev/video0/dev/video1$v4l2-ctl-d0--list-formats-extioctl:VIDIOC_ENUM_FMTIndex:0Type:VideoCapturePixelFormat:MJPG(compressed)Name:Motion-JPEGSize:Discrete640x480Interval:Discrete0.033s(30.000fps)Size:Discrete1280x720Interval:Discrete0.033s(30.000fps)Size:Discrete640x360Interval:Discrete0.033s(30.000fps)Size:Discrete352x288Interval:Discrete0.033s(30.000fps)Size:Discrete320x240Interval:Discrete0.033s(30.000fps)Size:Discrete176x144Interval:Discrete0.033s(30.000fps)Size:Discrete160x120Interval:Discrete0.033s(30.000fps)Index:1Type:VideoCapturePixelFormat:YUYVName:YUYV4:2:2Size:Discrete640x480Interval:Discrete0.033s(30.000fps)Interval:Discrete0.050s(20.000fps)Size:Discrete1280x720Interval:Discrete0.100s(10.000fps)Size:Discrete640x360Interval:Discrete0.033s(30.000fps)Size:Discrete352x288Interval:Discrete0.033s(30.000fps)Size:Discrete320x240Interval:Discrete0.033s(30.000fps)Size:Discrete176x144Interval:Discrete0.033s(30.000fps)Size:Discrete160x120Interval:Discrete0.033s(30.000fps)

GoCoding 个人实践的经验分享,可关注公众号!

脚注

[1] Ubuntu 18.04 LTS (Bionic Beaver): http://releases.ubuntu.com/bionic/

[2] GStreamer: https://gstreamer.freedesktop.org/

[3] Installing on Linux: https://gstreamer.freedesktop.org/Documentation/installing/on-linux.html

[4] Command line tools: https://gstreamer.freedesktop.org/documentation/tools/index.html

[5] Plugins: https://gstreamer.freedesktop.org/documentation/plugins_doc.html

[6] GStreamer RTSP Server: https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server

[7] Stream webcam with GStreamer (RTSP): https://stackoverflow.com/questions/59068026/stream-webcam-with-gstreamer-rtsp

[8] x264 [error]: baseline profile doesnt support 4:2:2: http://gstreamer-devel.966125.n4.nabble.com/x264-error-baseline-profile-doesn-t-support-4-2-2-td4689099.html

[9] VLC: https://www.videolan.org/vlc/

[10] Modules/file: https://wiki.videolan.org/Documentation:Modules/file/

[11] Modules/v4l2: https://wiki.videolan.org/Documentation:Modules/v4l2/

[12] Streaming HowTo/Advanced Streaming Using the Command Line: https://wiki.videolan.org/Documentation:Streaming_HowTo/Advanced_Streaming_Using_the_Command_Line/

[13] Streaming HowTo/Command Line Examples: https://wiki.videolan.org/Documentation:Streaming_HowTo/Command_Line_Examples

[14] Ubuntu 18.04 Webcam streaming problem: https://askubuntu.com/questions/1224092/ubuntu-18-04-webcam-streaming-problem

[15] FFmpeg: http://www.ffmpeg.org/

[16] ffserver: http://trac.ffmpeg.org/wiki/ffserver

[17] Streaming RTSP with ffmpeg?: https://superuser.com/questions/1420328/streaming-rtsp-with-ffmpeg

[18] Run real time streaming with ffserver?: https://stackoverflow.com/questions/37403282/is-there-anyone-who-can-successfully-run-real-time-streaming-with-ffserver

TAGS标签:  rtsp  获取  方法  相关  工具  rtsp获取方法流相

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图