ffmpeg-webrtc(metartc)给ffmpeg添加webrtc协议

这个是使用metrtc的库为ffmpeg添加webrtc传输协议,目前国内还有一个这样的开源项目,是杨成立大佬,大师兄他们在做,不过wili页面维护的不好,新手不知道如何使用,我专门对它做过介绍,另一篇博文:ubuntu22.10 ffmpeg-webrtc推拉流srs环境搭建

后者目前还不支持whep(应该在开发中),因此推荐使用metartc的库。

首选它有三个第三方库,先编译这三个库。

版本commit 681b58754e9dd4bcfe79388ea73782705124c65b master

1.metartc6

2.srtp

3.ssl和crypto

4.编译ffmpeg

5.推流命令 WHIP

6.拉流命令 WHEP

7.测试

7.1配置srs

7.1推流

7.3拉流

笔者用的是ubuntu22.04默认gcc/g++是11

在编译srtp时报错,多重定义,其实是编译器版本过高,需要切换版本。

cpp 复制代码
sudo apt-get install gcc-9
sudo apt-get install g++-9
sudo ln -sf /usr/bin/gcc-9 /usr/bin/gcc
sudo ln -sf /usr/bin/g++-9 /usr/bin/g++

1.metartc6,这里有webrtc的传输协议。

cpp 复制代码
cd FFmpeg-n4.3.3/metartc6/metartc6
cd libmetartccore6
mkdir build
cd build
./cmake_x64.sh //x86_64
cp ./libmetartccore6.a ../../

2.srtp

cpp 复制代码
./configure
make -j20
cp libsrt2.a ../

3.openssl

cpp 复制代码
./config
make -j20
cp libcrypto2.a libssl2.a ../

4.编译ffmpeg,注意下面路径改为自己的路径

cpp 复制代码
./configure --enable-libx264 --enable-gpl --extra-libs='-L/home/yqw/temp/ffmpeg-webrtc/FFmpeg-n4.3.3/metartc6 -lmetartccore6 -lpthread -lsrtp2 -lssl -lcrypto -ldl'
make -j20
sudo make install

5.推流命令 WHIP

cpp 复制代码
ffmpeg ......-acodec opus -strict -2 -ar 48000 -f webrtc "url"
srs sample: whip url http://192.168.0.105:1985/rtc/v1/whip/?app=live&stream=livestream
cpp 复制代码
ffmpeg ......-acodec opus -strict -2 -ar 48000 -f webrtc "http://192.168.0.105:1985/rtc/v1/whip/?app=live&stream=livestream"
cpp 复制代码
ffmpeg ......-acodec opus -strict -2 -ar 48000 -f webrtc "webrtc://192.168.0.105:1985/rtc/v1/whip/?app=live&stream=livestream"
cpp 复制代码
./ffmpeg -re -i /path/test.mp4 -vcodec libx264 -acodec opus -strict -2 -ar 48000 -f webrtc "http://192.168.0.105:1985/rtc/v1/whip/?app=live&stream=livestream"

6.拉流命令 WHEP

cpp 复制代码
ffplay "webrtc://whep_url"
srs sample: whep url http://192.168.0.105:1985/rtc/v1/whip-play/?app=live&stream=livestream
cpp 复制代码
ffplay "webrtc://192.168.0.105:1985/rtc/v1/whip-play/?app=live&stream=livestream"

7.测试:

7.1拉取srs代码

srs,版本要求SRS version 5.0.153 or higher, or 6.0.43 or higher。

cpp 复制代码
https://github.com/ossrs/srs

编译srs后运行:

cpp 复制代码
./objs/srs -c conf/https.rtc.conf

7.2推流

cpp 复制代码
ffmpeg -re -i /home/yqw/t/juren-30s.mp4 -vcodec libx264 -acodec opus -strict -2 -ar 48000 -f webrtc "http://192.168.100.77:1985/rtc/v1/whip/?app=live&stream=livestream"

如果不要视频如下:

cpp 复制代码
ffmpeg -re -i /home/yqw/t/west.mp4 -vn -acodec opus -strict -2 -ar 48000 -f webrtc "http://192.168.100.77:1985/rtc/v1/whip/?app=live&stream=livestream"

7.3拉流

cpp 复制代码
ffplay "webrtc://192.168.100.77:1985/rtc/v1/whip-play/?app=live&stream=livestream"

附录:

libmetartccore2 来自于metaRTC-2.0.120.zip编译

对于2.0 commit 3b7034bbf3a9fbe5682733f0adf11763c75edf28

./ffmpeg -re -i /home/yqw/t/juren-30s.mp4 -vcodec libx264 -acodec opus -strict -2 -ar 48000 -f webrtc "webrtc://192.168.100.77:1985/live/livestream"

./ffplay webrtc://192.168.100.77:1985/live/livestream

相关推荐
jndingxin5 小时前
OpenCV视频I/O(8)视频采集类VideoCapture之从视频源中读取一帧图像函数read()的使用
人工智能·opencv·音视频
SEU-WYL6 小时前
基于深度学习的视频生成
人工智能·深度学习·音视频
小神.Chen9 小时前
YouTube音视频合并批处理基于 FFmpeg的
ffmpeg·音视频
EasyCVR13 小时前
安防监控/视频系统EasyCVR视频汇聚平台如何过滤134段的告警通道?
网络协议·音视频·视频编解码·视频监控·gb28181
Q83431581920 小时前
华为 海思22AP10(SS524)H.265 编解码处理器用户指南
arm开发·人工智能·嵌入式硬件·音视频·硬件工程·h.265·视频编解码
PlumCarefree20 小时前
mp4(H.265编码)转为本地RTSP流
音视频·harmonyos·h.265
Lijunyan129821 小时前
Python、C++、java阶乘算法
python·其他·音视频·twitter·segmentfault
顶顶年华正版软件官方1 天前
小红书制作视频如何去原视频音乐,视频如何去原声保留背景音乐?
音视频·视频剪辑·会声会影
2的n次方_1 天前
【AIGC】内容创作——AI文字、图像、音频和视频的创作流程
人工智能·ai·音视频
fpcc1 天前
录制真人出镜视频一个简单方法
智能手机·音视频