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

我的音视频/流媒体开源项目(github)

RTSP系列:

        RTSP系列一:RTSP协议介绍

        RTSP系列二:RTSP协议鉴权

        RTSP系列三:RTP协议介绍

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

目录

一、RTSP Server实战项目

1、准备

2、simple-rtsp-server下载编译

3、运行

4、拉流测试

二、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、运行

测试程序运行参数:
./rtsp_server_file auth(鉴权 0-not authentication; 1-authentication) loop(文件回放循环控制 0-not loop 1-loop) dir_path(指定文件夹路径 default:./mp4path)
 
运行:
./rtsp_server_file 1 1 ../mp4path/

4、拉流测试

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

TCP拉流:
ffmpeg -rtsp_transport tcp -i "rtsp://admin:123456@192.168.10.17:8554/test_h264_aac.mp4" -vcodec copy -acodec copy  test_h264_aac_tcp.mp4
 
UDP拉流:
ffmpeg -i "rtsp://admin:123456@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信令交互过程更加清晰。

  simple-rtsp-server除了自带的文件回放功能,也可添加自定义rtsp会话并添加音视频源,自定义的视频源可以来自文件、网络收到的媒体流,也可以是从V4L2(视频)、ALSA(音频)获取的实时音视频。

  simple-rtsp-server也可以去掉内置的文件回放功能(注释掉CMakeLists.txt中的set(RTSP_FILE_SERVER FORCE)),即只能添加自定义rtsp会话和音视频源。去掉文件回放功能,项目将不再依赖ffmpeg,可以基于simple-rtsp-server实现自己的rtsp server。

二、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。

posted @   BreakingY  阅读(22)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示