ffmpeg - 在不中断 rtmp 流的情况下更新 ffmpeg 过滤器

标签 ffmpeg rtmp fluent-ffmpeg

我正在使用 ffmpeg 读取 rtmp 流,添加一个过滤器(例如模糊框)并创建一个不同的 rtmp 流。
例如,命令如下所示:

ffmpeg -i <rtmp_source_url> -filter_complex "split=2[a][b];[a]crop=w=300:h=300:x=0:y=0[c];[c]boxblur=luma_radius=10:luma_power=1[blur];[b][blur]overlay=x=0:y=0[output]" -map [output] -acodec aac -vcodec libx264 -tune zerolatency -f flv <rtmp_output_url>
其中 rtmp_source_url 是相机/无人机发送通量的位置,而 rtmp_output_url 是带有模糊框的结果视频。
模糊框需要移动,因为目标移动或相机移动了。
我想在不中断输出流的情况下这样做。
我正在使用 fluent-ffmpeg 创建 ffmpeg 进程,而程序的不同部分计算模糊框的位置。
感谢您的帮助和时间!

最佳答案

考虑使用管道来拆分处理。
见这里 - https://ffmpeg.org/ffmpeg-protocols.html#pipe

The accepted syntax is:

pipe:[number]
number is the number corresponding to the file descriptor of the pipe (e.g. 0 for stdin, 1 for stdout, 2 for stderr). If number is not specified, by default the stdout file descriptor will be used for writing, stdin for reading.

For example to read from stdin with ffmpeg:

cat test.wav | ffmpeg -i pipe:0
# ...this is the same as...
cat test.wav | ffmpeg -i pipe:
For writing to stdout with ffmpeg:

ffmpeg -i test.wav -f avi pipe:1 | cat > test.avi
# ...this is the same as...
ffmpeg -i test.wav -f avi pipe: | cat > test.avi
例如,您读取一个 rtmp 流,添加一个过滤器(如模糊框)并创建一个不同的 rtmp 流。所以,第一步是分离传入和传出流 -
ffmpeg -i <rtmp_source_url> -s 1920x1080 -f rawvideo pipe: | ffmpeg -s 1920x1080 -f rawvideo -y -i pipe: -filter_complex "split=2[a][b];[a]crop=w=300:h=300:x=0:y=0[c];[c]boxblur=luma_radius=10:luma_power=1[blur];[b][blur]overlay=x=0:y=0[output]" 
-map [output] -acodec aac -vcodec libx264 -tune zerolatency -f flv <rtmp_output_url>
我不知道你有什么标准来改变模糊框,但现在你可以在第二个 ffmpeg 中处理传入的帧。另外,我使用了1920x1080作为视频大小 - 您可以将其替换为实际大小。
对于第一次迭代,不要担心音频,做你的模糊操作。我们正在喂食rawvideo - 在本例中,音频将被忽略。

关于ffmpeg - 在不中断 rtmp 流的情况下更新 ffmpeg 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69220124/

相关文章:

html - 可以使用带有 HTML5 播放器的 Amazon S3/CloudFront 流式传输视频吗?

gstreamer - 使用 GStreamer 转发 rtmp 流

node.js - 无法让 FFMPEG buildpack 在 Heroku Node.js 服务器中工作(使用 Fluent-FFMPEG)

bash - 使用 mkfifo 和传输流,这可能吗?

vue.js - 将大视频上传到 GCS 使用签名网址,但视频已损坏

cordova - 如何在 phonegap Cordova :video extension SDP 中播放 RTMP 视频

node.js - 将流从 Fluent-ffmpeg 传递到 Google Cloud Storage

android - 无法在 TextureView Android 中播放视频

java - FFMPEG 未找到