RTSP系列四:RTSP Server/Client实战项目

RTSP系列:

RTSP系列一:RTSP协议介绍-CSDN博客

RTSP系列二:RTSP协议鉴权-CSDN博客

RTSP系列三:RTP协议介绍-CSDN博客

RTSP系列四:RTSP Server/Client实战项目-CSDN博客

目录

[一、RTSP Server实战项目](#一、RTSP Server实战项目)

1、准备

2、simple-rtsp-server下载编译

3、运行

4、拉流测试

[二、RTSP Client实战项目](#二、RTSP Client实战项目)

1、编译

2、测试


一、RTSP Server实战项目

地址:https://github.com/BreakingY/simple-rtsp-server

使用epoll,支持RTP OVER UDP、RTP OVER TCP,支持H264/H265、AAC/PCMA、支持鉴权。

1、准备

simple-rtsp-server依赖ffmpeg,版本要求>=4.x。支持系统:Linux

依赖安装:

复制代码
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev

汇编库:
sudo apt-get install yasm
sudo apt-get install nasm
 
视频库:
sudo apt-get install libx264-dev
sudo apt-get install libx265-dev
 
音频库:
sudo apt-get install libfdk-aac-dev
sudo apt-get install libmp3lame-dev
sudo apt-get install libopus-dev

ffmpeg源码下载:

复制代码
wget https://ffmpeg.org//releases/ffmpeg-4.0.5.tar.bz2
 
tar xjvf ffmpeg-4.0.5.tar.bz2
 
cd ffmpeg-4.0.5

编译安装:

复制代码
./configure --prefix=/usr/local --enable-libx264 --disable-x86asm --enable-nonfree --enable-libfdk-aac  --enable-shared --enable-gpl --enable-libmp3lame --enable-libopus  --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
 
make
 
make install

2、simple-rtsp-server下载编译

复制代码
git clone https://github.com/BreakingY/simple-rtsp-server.git
 
cd simple-rtsp-server
 
mkdir build
 
cd build
 
cmake ..
 
make -j

3、运行

复制代码
cp -r ../mp4path .
 
./rtsp_server 0 (0-不鉴权;1-鉴权)

4、拉流测试

项目中mp4path自带了测试文件,后面把想回放的视频放到mp4path中即可

复制代码
TCP拉流:
ffmpeg -rtsp_transport tcp -i "rtsp://192.168.10.17:8554/test_h264_aac.mp4" -vcodec copy -acodec copy  test_h264_aac_tcp.mp4
 
UDP拉流:
ffmpeg -i "rtsp://192.168.10.17:8554/test_h264_aac.mp4" -vcodec copy -acodec copy  test_h264_aac_udp.mp4

也可通过VLC直接播放,点击媒体->打开网络串流,输入rtsp地址即可。默认是udp拉流,要使用TCP需要打开工具->偏好设置->输入/编解码器,拉到最下方,选择"RTP over RTSP(TCP)"

rtsp_server程序会把rtsp信令交互过程打印出来,让我们对rtsp信令交互过程更加清晰。

二、RTSP Client实战项目

地址:https://github.com/BreakingY/simple-rtsp-client

支持RTP OVER UDP、RTP OVER TCP,支持H264/H265、AAC/PCMA、支持鉴权。

不需要任何依赖。

1、编译

复制代码
git clone https://github.com/BreakingY/simple-rtsp-client.git

mkdir build

cd build

cmake ..

make -j

2、测试

复制代码
./rtsp_client rtsp_url

客户端会把收到的音视频写入文件,H264/H265写入到test_out.h26x,AAC写入到test_out.aac,PCMA写入到test_out.pcma。

相关推荐
卓豪终端管理1 分钟前
从安全配置开始,构建主动防御体系
运维·网络·安全
-Excalibur-4 分钟前
ARP RIP OSPF BGP DHCP以及其他计算机网络当中的通信过程和广播帧单播帧的整理
c语言·网络·python·学习·tcp/ip·算法·智能路由器
-Excalibur-9 分钟前
关于计算机网络当中的各种计时器
java·c语言·网络·c++·笔记·python·计算机网络
量子罐头10 分钟前
戴尔PowerEdge R730服务器100G网卡选型推荐及实测分析
网络
FreeBuf_13 分钟前
育碧《彩虹六号:围攻》服务器遭入侵事件与MongoBleed漏洞关联
服务器·网络·安全
乾元13 分钟前
当网络变成博弈场:混合云时代,如何用 AI 重构跨域链路的成本与体验平衡
运维·网络·人工智能·网络协议·安全·华为·重构
云老大TG:@yunlaoda36013 分钟前
华为云国际站代理商MSGSMS主要有什么作用呢?
网络·人工智能·华为云
运维闲章印时光18 分钟前
单位本部与分部网络已实现互联互通,网络访问通畅,数据传输正常
开发语言·网络·php
停在你这里.18 分钟前
UDS诊断之 22服务
网络
AC赳赳老秦1 小时前
DeepSeek教育科技应用:智能生成个性化学习规划与知识点拆解教程
前端·网络·数据库·人工智能·学习·matplotlib·deepseek