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

前提

GStreamer

安装:

sudo apt 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-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

查看所有插件:

# conda deactivate
gst-inspect-1.0 -a

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

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

播放 /dev/video0 webcam:

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

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

GStreamer RTSP Server

编译 test-launch 例子:

sudo apt install libgstreamer1.0-dev libgstrtspserver-1.0

git clone https://github.com/GStreamer/gst-rtsp-server.git

cd gst-rtsp-server/
git checkout 1.18 cd examples/
gcc test-launch.c -o test-launch $(pkg-config --cflags --libs gstreamer-rtsp-server-1.0)

test-launch 发送 RTSP 测试流:

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

gst-launch 接收 RTSP 测试流:

gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test

发送 RTSP,以 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=640,height=480 ! videoconvert ! x264enc ! rtph264pay name=pay0 pt=96"

接收 RTSP,以 gst-launch

gst-launch-1.0 playbin uri=rtsp://127.0.0.1:8554/test
# or
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test ! decodebin ! autovideosink

参考

VLC

安装:

sudo snap install vlc
# allow camera permission
snap connect vlc:camera :camera

查看可用模块:

vlc --list

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

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

播放 /dev/video0 webcam:

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

发送 RTSP,以 vlc

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

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

发送 /dev/video0 webcam:

vlc v4l2:///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

vlc rtsp://127.0.0.1:8554/test

参考

FFmpeg

安装:

sudo apt install ffmpeg

发送 RTSP,以 ffserver

配置 ffserver.conf

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

开启 ffserver

$ nohup ffserver -f ffserver.conf &

$ tail nohup.out
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
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 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Wed Apr 21 11:28:39 2021 Opening feed file '/home/john/Videos/test.mp4' for stream 'test.mp4'
Wed Apr 21 11:28:39 2021 FFserver started.

接收 RTSP,以 ffplay

ffplay rtsp://127.0.0.1:1554/test.mp4

参考

关于 Media

$ sudo apt install ffmpeg

$ ffprobe ~/Videos/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)
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-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
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 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/john/Videos/test.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:10:22.04, start: 0.000000, bitrate: 4205 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 4204 kb/s, 25 fps, 25 tbr, 1200k tbn, 2400k tbc (default)
Metadata:
handler_name : VideoHandler

关于 Webcam

$ sudo apt install v4l-utils

$ v4l2-ctl --list-devices
HD Webcam: HD Webcam (usb-0000:00:14.0-13):
/dev/video0
/dev/video1 $ v4l2-ctl -d 0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 352x288
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 176x144
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 160x120
Interval: Discrete 0.033s (30.000 fps) Index : 1
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.100s (10.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 352x288
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 176x144
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 160x120
Interval: Discrete 0.033s (30.000 fps)

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

RTSP 流相关工具介绍的更多相关文章

  1. nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器

    本文概要: nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择.本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也叫rtsp转播,数据源不是读取文件,而是采用 ...

  2. 用VLC读取摄像头产生RTSP流,DSS主动取流转发(一)(二) 【转】

    http://blog.csdn.net/fm0517/article/details/38110633 http://blog.csdn.net/fm0517/article/details/381 ...

  3. 用VLC读取摄像头产生RTSP流,DSS侦听并转发(二)

    用VLC读取摄像头产生RTSP流,DSS侦听并转发(二) 之前介绍过<用VLC读取摄像头产生RTSP流,DSS主动取流转发(一)>本文介绍另一种方法. 摄像机地址是192.1.101.51 ...

  4. FFmpeg开发笔记(九):ffmpeg解码rtsp流并使用SDL同步播放

    前言   ffmpeg播放rtsp网络流和摄像头流.   Demo   使用ffmpeg播放局域网rtsp1080p海康摄像头:延迟0.2s,存在马赛克     使用ffmpeg播放网络rtsp文件流 ...

  5. 使用vlc播放器播放rtsp流视频

    可参考: 使用vlc播放器做rtsp服务器 web网页中使用vlc插件播放相机rtsp流视频 使用vlc进行二次开发做自己的播放器 首先需要安装vlc播放器,下载及安装步骤略 使用vlc播放器播放rt ...

  6. web网页中使用vlc插件播放相机rtsp流视频

    可参考: 使用vlc播放器做rtsp服务器 使用vlc播放器播放rtsp视频 使用vlc进行二次开发做自己的播放器 vlc功能还是很强大的,有很多的现成的二次开发接口,不需配置太多即可轻松做客户端播放 ...

  7. 用vlc SDK创建一个播放视频文件和RTSP流视频的Demo

    #include <stdio.h> #include <tchar.h> #include <time.h> #include <windows.h> ...

  8. Storm流分组介绍

    Storm流分组介绍                流分组是拓扑定义的一部分,每个Bolt指定应该接收哪个流作为输入.流分组定义了流/元组如何在Bolt的任务之间进行分发.在设计拓扑的时候需要定义数据 ...

  9. VS2015编译FFMPEG,修改FFmpeg缓冲区大小解决实时流解码丢包问题,FFmpeg错误rtsp流地址卡死的问题,设置超时

    之前尝试过很多网上利用Windows编译FFmpeg的文章,都没有办法编译X64位的FFmpeg,有些教程中有专门提到编译64位的FFmpeg需要下载mingw-w64-install,但是编译的过程 ...

随机推荐

  1. MVVM中的vm双向监听和mvc的缺点

    `MVVM`模型: - 即Model,模型,包括数据和一些基本操作 - 即View,视图,页面渲染结果- 即View-Model,模型与视图间的双向操作(无需开发人员干涉) `MVVM`中的`VM`要 ...

  2. Ping 的工作原理你懂了,那 ICMP 你懂不懂?

    计算机网络我也连载了很多篇了,大家可以在我的公众号「程序员cxuan」 或者我的 github 系统学习. 计算机网络第一篇,聊一聊网络基础 :计算机网络基础知识总结 计算机网络第二篇,聊一聊 TCP ...

  3. Linux系统管理--part(1)

    Linux系统管理--part(1) Linux系统安装完毕,需要对Linux系统进行管理和维护,让Linux服务器能够真正英语于企业中 Linux运维的三个步骤安装.调试.启动 通过本篇文章,将学习 ...

  4. 音视频+ffmpeg

    雷霄骅:https://me.csdn.net/leixiaohua1020 致敬! 1.[总结]视音频编解码技术零基础学习方法 https://blog.csdn.net/leixiaohua102 ...

  5. ElasticSearch 集群安全

    公号:码农充电站pro 主页:https://codeshellme.github.io 在安装完 ES 后,ES 默认是没有任何安全防护的. ES 的安全管理主要包括以下内容: 身份认证:鉴定访问用 ...

  6. 《吃透MQ系列》核心基础全在这里了

    这是<吃透XXX>技术系列的开篇,这个系列的思路是:先找到每个技术栈最本质的东西,然后以此为出发点,逐渐延伸出其他核心知识.所以,整个系列侧重于思考力的训练,不仅仅是讲清楚 What,而是 ...

  7. 无限可能 | Flutter 2 重点更新一览

    我们非常高兴在本周发布了 Flutter 2.自 Flutter 1.0 发布至今已有两年多的时间,在如此短暂的时间内,我们解决了 24,541 个 issue,合并了来自 765 个贡献者的 17, ...

  8. JS的this指向深入

    this指向深入 this的绑定规则 默认绑定 this默认指向了window 全局环境下this指向了window 函数独立调用,函数内部的this也指向了window <script> ...

  9. The Red Button

    The Red Button 问题 问题描述 Piegirl终于发现了红色按钮,你现在还剩最后一个机会去改变这个结局.这个按钮下面的电路由n个从0到n-1编号节点组成.为了关闭这个按钮,这n个节点必须 ...

  10. C# 应用 - 使用 HttpListener 接受 Http 请求

    1. 库类: \Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll System.Net.HttpListen ...