快速搭建rtsp server(Ubuntu)

        在现代视频监控和实时视频流媒体应用中,实时流协议(RTSP)服务器扮演着至关重要的角色。无论是家庭安防系统、企业级监控还是流媒体服务,RTSP服务器都能提供高效、稳定的解决方案。然而,对于许多初学者或开发者来说,搭建一个功能完善的RTSP服务器似乎是一个复杂且耗时的任务。

        这里将使用simple-rtsp-server快速搭建rtsp server,simple-rtsp-server从文件中读取音视频发送给客户端,文件格式支持MP4、MKV;音视频支持H264、H265、AAC、PCMA;支持rtp over udp、rtp over tcp,使用epoll发送音视频数据。纯C语言实现,简单高效,搭建方便,只需把要回放的视频放到mp4path路径下中,就可以通过”rtsp://ip:8554/mp4文件名字“地址进行拉流了,文件结束后会自动循环,不同客户端请求同一个rtsp地址时,客户端收到的音视频是同步的,这一点和真实摄像头是一样的。项目地址:https://github.com/BreakingY/simple-rtsp-server 。

1、准备

        simple-rtsp-server依赖ffmpeg,版本要求>=4.x。

        依赖安装:

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

        源码下载:

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

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信令交互过程更加清晰。

相关推荐

  1. Hadoop快速指南

    2024-06-07 08:02:04       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-07 08:02:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-07 08:02:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-07 08:02:04       87 阅读
  4. Python语言-面向对象

    2024-06-07 08:02:04       96 阅读

热门阅读

  1. 【LeetCode 74】搜索二维矩阵

    2024-06-07 08:02:04       31 阅读
  2. npm发布自己的插件包指南

    2024-06-07 08:02:04       32 阅读
  3. Python语言证明:探索编程之道的奥秘

    2024-06-07 08:02:04       28 阅读
  4. Hive 面试题(三)

    2024-06-07 08:02:04       25 阅读
  5. appium

    appium

    2024-06-07 08:02:04      29 阅读
  6. 什么是函数?在C语言中如何定义一个函数

    2024-06-07 08:02:04       27 阅读