video - 使用 ffmpeg 进行慢速 VP8 和 VP9 编码

标签 video ffmpeg stream transcoding

我看到了this回答,但它有点旧。也许情况发生了变化?

我想使用 ffmpeg 将来自 IP 摄像机的流重新编码为 WebM(VP8 或 VP9)格式。我需要实时速度,但我的 CPU 是 Core i5 (2017) 并且太忙了(平均负载超过 100%)。

  • 我可以购买更适合此类编码任务的硬件吗?

  • 建议实时转码使用 ffmpeg 的哪些参数?

目前我正在使用这个命令(使用覆盖色度键):

./ffmpeg \
-i \
bg.jpg \
-thread_queue_size 512 \
-rtsp_transport tcp -i rtsp://ip_cam:port/stream \
-codec:v libvpx -quality realtime -r 25 -crf 30 \
-b:v 2M -qmin 10 -qmax 50 -maxrate 2.5M -bufsize 5M \
-speed 1 \
-b:v 2M \
-cpu-used 0 -threads 4 \
-auto-alt-ref 0 \
-c:a libopus -b:a 96k \
-filter_complex "[1:v]chromakey=0x70de77:0.1:0.0[ckout];[0:v][ckout]overlay[out]" \
-map "[out]" \
-f webm udp://ip_destination:1935/name/stream

最佳答案

VP8/VP9 的速度/质量选项在 the documentation 中有解释。 .请注意,在 ffmpeg 中,您必须以不同方式指定参数(参见 ffmpeg -h encoder=libvpx-vp9):

  • CPU 使用率:
    • ffmpeg:-cpu-used(旧选项:-speed)
    • libvpx: --cpu-used
  • 质量/截止日期:
    • ffmpeg:-deadline realtime-deadline good(旧选项:-quality)
    • libvpx: --rt, --good

-cpu-used 应该是您的主要控制旋钮。虽然默认值为 0,但文档指出:

Setting --cpu-used=1 or --cpu-used=2 will give further significant boosts to encode speed, but will start to have a more noticeable impact on quality and may also start to effect the accuracy of the data rate control.

Setting a value of 4 or 5 will turn off "rate distortion optimisation" which has a big impact on quality, but also greatly speeds up the encoder.

特别是对于实时编码,您需要设置-deadline realtime:

--rt Real-time mode allows the encoder to auto adjust the speed vs. quality trade-off in order to try and hit a particular cpu utilisation target. In this mode the --cpu-used parameter controls the %cpu target as follows:

target cpu utilisation = (100*(16-cpu-used)/16)%

Legal values for -cpu-used when combined with --rt mode are (0-15).

It is worth noting that in --rt mode the encode quality will depend on how hard a particular clip or section of a clip is and how fast the encoding machine is. In this mode the results will thus vary from machine to machine and even from run to run depending on what else you are doing.

当然,对于 i5 CPU,根据您拥有的并行转码任务数量、您想要达到的质量水平以及最终延迟应该是多少,投资购买最新 Intel i7 系列的强大 CPU有道理。

英特尔的 Kaby Lake 芯片显然通过英特尔 QuickSync 和 ffmpeg 支持硬件辅助编码 supports that through VA-API .

关于video - 使用 ffmpeg 进行慢速 VP8 和 VP9 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44850269/

相关文章:

ios - 是否可以在让用户与应用程序交互的同时上传视频?

ios - 如何将视频像图片一样放置

android - Facebook SDK 3.0 在android中上传视频

php - 在一个人无法完全控制的主机上安装 ffmpeg?+

node.js - 带字符串的 readObjectMode

android - 由 Media Player 播放的实时 mp3 流无需缓冲

linux - 从脚本生成视频(concat 和简单效果)

python - 通过 pip 全新安装 OpenCV 后,它会抛出 ImportError : DLL load failed

ffmpeg - 来自 7z 文件的 SHA256 与 FFMPEG 下载 SHA 不匹配

python - Boto逆流