为什么 FFmpeg 使用条带进行转码

Why FFmpeg transcode with strips

提问人:Андрей Тернити 提问时间:9/14/2023 最后编辑:Андрей Тернити 更新时间:9/15/2023 访问量:57

问:

我有MJPEG视频。我想获取 VP9 webm 视频。

ffmpeg -loglevel verbose -i "input.yuvj422p" -pix_fmt yuv420p -c:v libvpx-vp9 -crf 20 -b:v 0 constantQualityExample.webm

它工作正常(右图),日志:

[mjpeg @ 0x55b9b4b7ea40] Format mjpeg detected only with low score of 25, misdetection possible!
Input #0, mjpeg, from 'input.yuvj422p':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mjpeg (Baseline), 1 reference frame, yuvj422p(pc, bt470bg/unknown/unknown, center), 1280x720 [SAR 1:1 DAR 16:9], 25 tbr, 1200k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0x55b9b4ba4a00] w:1280 h:720 pixfmt:yuvj422p tb:1/1200000 fr:25/1 sar:1/1
[auto_scaler_0 @ 0x55b9b4ba7c00] w:iw h:ih flags:'bicubic' interl:0
[format @ 0x55b9b4ba5800] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[swscaler @ 0x55b9b4ba8b00] deprecated pixel format used, make sure you did set range correctly
[auto_scaler_0 @ 0x55b9b4ba7c00] w:1280 h:720 fmt:yuvj422p sar:1/1 -> w:1280 h:720 fmt:yuv420p sar:1/1 flags:0x4
[libvpx-vp9 @ 0x55b9b4b85840] v1.7.0
[libvpx-vp9 @ 0x55b9b4b85840] --prefix=/usr --enable-pic --enable-shared --disable-install-bins --disable-install-srcs --size-limit=16384x16384 --enable-postproc --enable-multi-res-encoding --enable-temporal-denoising --enable-vp9-temporal-denoising --enable-vp9-postproc --target=x86_64-linux-gcc
Output #0, webm, to 'constantQualityExample.webm':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: vp9 (libvpx-vp9), 1 reference frame, yuv420p(center), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.91.100 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
No more output streams to write to, finishing.
Automatically inserted bitstream filter 'vp9_superframe'; args=''

但我想要 libav 也是如此。我以官方为例,并进行了一些更改以使代码变得简单(删除音频功能,删除多视频流功能),我的代码在这里。但它会生成带有条带的视频并删除最后一帧(左图)。在此处输入图像描述 Mediainfo:我的示例日志: enter image description here

Input #0, jpeg_pipe, from 'input.yuvj422p':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn
[libvpx-vp9 @ 0x5593e186fa80] v1.11.0
Output #0, webm, to 'VideoOut.webm':
  Stream #0:0: Video: vp9, yuv420p(unknown/bt470bg/unknown), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 tbn
[swscaler @ 0x5593e221af00] deprecated pixel format used, make sure you did set range correctly

我应该在我的代码中更改什么以获得像 ffmpeg 这样的正常结果?

C FFMPEG YUV LIBAV 转码

评论


答:

0赞 Ronald S. Bultje 9/14/2023 #1

关于乱七八糟的颜色,看起来您的输入文件是 yuv422,而 VP9 默认需要 420 作为输入格式。您需要一个色彩空间转换器(在命令行中),例如过滤器链中的“format=yuv420p”。-pix_fmt yuv420p

关于丢失的最后一帧,我猜你的链中的一个项目缓存了一个图像。以 dec、filter 和 enc 为单位对输入/输出进行计数,以查看哪个输入/输出不匹配,您将知道哪个要刷新更多。