ffmpeg - 如何使用 ffmpeg 流式传输到多个目的地

标签 ffmpeg video-streaming ubuntu-16.04

我想将我的视频流式传输到 4 个目的地。我的输入信号需要重新编码为“H.264 AAC”,所以我想将它发送到我的服务器。这已经奏效了。

Client -> Server with ffmpeg -> Destinations
现在我遇到了一个性能问题:一个应该得到 1080p 的流,两个应该得到 720p。
因此,首先以所需格式 H.264 1080p 和 30 FPS 的 AAC 获取流,然后计算一次流,将其 1:1 发送到两个高清目标是有意义的。
并并行创建一个 720p 流并将其发送到剩余的两个目的地。
上执行此操作的最佳方法是什么? Ubuntu 16.04机器 ?
我之前的做法:
ffmpeg -i rtmp://livestream.domain.example/live/<key> \
-threads 2 -s hd1080 -preset veryfast -f flv rtmp://destination1.example/live2/<key> \
-threads 2 -s hd1080 -preset veryfast -f flv rtmp://destination2.example/live2/<key> \
-threads 1 -s hd720 -c:v libx264 -c:a aac -preset veryfast -r 30 -g 60 -b:v 3000k -f flv rtmp://destination3.example/x/<key> \
-threads 1 -s hd720 -c:v libx264 -preset veryfast -c:a aac -f flv 'rtmps://destination4.exmple/rtmp/<key>'
你可以看到代码中的重复。 :-/

最佳答案

使用 tee muxer :

ffmpeg -i rtmp://livestream.domain.example/live/<key> \
-filter_complex "[0:v]scale=-2:1080,fps=30,split=outputs=2[1080a][1080b];[0:v]scale=-2:720,fps=30,split=outputs=2[720a][720b]" \
-map "[1080a]" -map "[1080b]" -map "[720a]" -map "[720b]" -map 0:a \
-c:v libx264 -c:a aac -preset veryfast -g 60 -b:v 3000k -maxrate 3000k -bufsize 6000k -f tee \
"[select=\'v:0,a\':f=flv:onfail=ignore]rtmp://destination1.example/live2/<key>| \
 [select=\'v:1,a\':f=flv:onfail=ignore]rtmp://destination2.example/live2/<key>| \
 [select=\'v:2,a\':f=flv:onfail=ignore]rtmp://destination3.example/live2/<key>| \
 [select=\'v:3,a\':f=flv:onfail=ignore]rtmp://destination4.example/live2/<key>"

关于ffmpeg - 如何使用 ffmpeg 流式传输到多个目的地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64526331/

相关文章:

audio - 如何使用 ffmpeg 在特定位置后延迟音频?

html - 使用 SuperWebSocket 进行视频流传输或最大数据传输的最佳选择是什么

unix - 如何将帧写入视频文件?

ffmpeg - 从 RTMP 流中实时提取帧作为图像

ubuntu - 在 Ubuntu 16 上运行 CouchDB 的 emfile 错误

ffmpeg - 将视频文件容器更改为 mp4

ffmpeg - VLC 和 ffmpeg 如何协同工作?

php - 波形不如应有的平滑

c++ - 库 Poco : DSO missing from command line

orientdb - systemd 在 Ubuntu 16.04 上启动后立即停止 OrientDB