本教程讲解如何基于TB-RK3399proD开发板进行RTSP推流,并可在远程使用vlc进行播放
本教程demo为教学用例,进行3小时拷机测试正常,若用户想商用还需自行优化;用户也可以使用其他推流框架配合rockchip mpp编解码库进行RTSP推流
开发板:TB-RK3399proD
系统、固件:采用fedora28系统(固件v1.5测试通过),Debian10测试通过
推流框架:live555
编解码库:rockchip mpp编解码库
图像数据:usb摄像头
1. 环境安装
fedora28系统
- sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
- sudo dnf install live555-devel
- sudo dnf install ffmpeg-devel
- sudo dnf install librockchip_mpp-devel
- sudo dnf install librockchip_rga-devel
Debian10系统 - 第一次更新:
- 1. 更新源:sudo apt update --fix-missing
- 2. 升级软件包:sudo apt -y upgrade
- 注意:升级过去中会有提示确认是否提供/etc/apt/sources.list.d/toybrick.list,请输入"Y"
- 3. 再次更新源:sudo apt update
- 后续更新:
- sudo apt update
- sudo apt upgrade
- 安装依赖:
- sudo apt install liblivemedia-dev
- sudo apt install livemedia-utils
- sudo apt install ffmpeg
- sudo apt install libavcodec-dev
- sudo apt install libswscale-dev
- sudo apt install libavformat-dev
- sudo apt install vlc
- sudo apt install rockchip-mpp-dev
- sudo apt install rockchip-rga-dev
2.下载并解压附件 for fedora for debian
3. 编译执行
- cd IPCamera/
- make clean
- make
- ./RTSPServer
运行时会打印URL地址,ip不固定,所以以实际打印为准,我这里是"rtsp://172.16.9.3:8554/h264ESVideoTest",后续播放就使用该地址
4.使用vlc进行播放,我这里直接在板子上安装vlc,用户也可以在PC上使用vlc播放 "media"--"Open Network Stream"--"rtsp://172.16.9.3:8554/h264ESVideoTest"--"Play"
运行效果如下
代码分析
V4L2.cpp
- void V4L2FramedSource::doGetNextFrame()
- {
- long bigin = get_time();
- registerOutputInterest();
- while(fTotOfFrameToSend<fMaxOfFrameToSend)
- {
- convernt_to_OutputBuffer();
- }
- long end = get_time();
- printf("V4L2FramedSource::doGetNextFrame use %d \n", end - bigin);
- //统计返回信息
- fFrameSize=fNumValidDataBytes;//一次一帧图像
- fNumTruncatedBytes = 0;
- reset();
- afterGetting(this);
- }
从usb摄像头获取一帧数据,转化成NV12格式
StreamEncoder.cpp
- void StreamEncoder::continueReadProcessing1(unsigned frameSize,unsigned numTruncatedBytes,
- struct timeval presentationTime,
- unsigned durationInMicroseconds){
- fNumTruncatedBytes = numTruncatedBytes;
- fPresentationTime = presentationTime;
- fDurationInMicroseconds = durationInMicroseconds;
- encoder_to_h264();
- if(fNumValidDataBytes+dstsize<fOutputBufferSize && fTotOfFrameToSend<fMaxOfFrameToSend)
- {
- copy_to_outputbuffer();
- }
- fFrameSize = fNumValidDataBytes;
- gettimeofday(&fPresentationTime, NULL);
- reset();
- FramedSource::afterGetting(this);
- }
使用 rockchip mpp库进行h264编码
|