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

相关推荐
xierui1231239 小时前
视频Agent的声音编排:原声、TTS、ASR与背景音乐怎样分工
人工智能·音视频
HY小宝F10 小时前
智能摄像头系统 30 天学习计划 Day 09:用 RTSP 把视频送到网络
网络·学习·音视频
美狐美颜SDK开放平台20 小时前
准备开发直播APP?视频美颜SDK接入前的十项检查清单
android·ios·音视频·直播美颜sdk·视频美颜sdk
企业数字化笔记21 小时前
视频人体姿态怎么做三维可视化?2D关键点、深度局限与技术选型
人工智能·算法·音视频
昨日之日20061 天前
MiniMax-H3 V7(FastH3 Omni):8步生成带声视频,比原版快近10倍。参考图、视频、声音全都能用!
人工智能·计算机视觉·音视频·1024程序员节
物联网老王1 天前
音频外设元器件与外设接口综合速查表
音视频
AIsoft_86891 天前
手机视频转文字工具清单:哪些APP支持录屏识别
android·音视频
2601_955662461 天前
小说推文如何制作多人配音?从角色划分到音频生成
人工智能·音视频·语音识别·媒体·视频
AI视频工具指南2 天前
怎么用 AI 做悬疑短剧?
人工智能·aigc·音视频
技灵AI2 天前
AI 口播视频提示词怎么写?让人物讲解和产品展示更自然
人工智能·音视频