FFmpeg 视频转码输出矩形状劣质像素

FFmpeg 视频转码输出矩形状劣质像素

我正在尝试使用以下命令通过 FFmpeg 转换视频:

ffmpeg -i input.AVI -vf yadif output.mp4

原始视频如下: 输入

输出是这样的,在视频中情况逐渐恶化: 输出

完整命令行输出:

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'D:/samples/GSchneller.AVI':
  Duration: 00:00:48.00, start: 0.000000, bitrate: 4549 kb/s
    Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuv420p(top first), 720x576 [SAR 1:1 DAR 5:4], 4426 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Stream #0:1: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 8000 Hz, mono, u8, 64 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_u8 (native) -> aac (native))
Press [q] to stop, [?] for help
[aac @ 0000021440118640] Too many bits 8832.000000 > 6144 per frame requested, clamping to max
[libx264 @ 0000021440115c80] using SAR=1/1
[libx264 @ 0000021440115c80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000021440115c80] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0000021440115c80] 264 - core 158 r2984 3759fcb - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'D:/samples/output.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 720x576 [SAR 1:1 DAR 5:4], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 48 kb/s
    Metadata:
      encoder         : Lavc58.54.100 aac
frame= 1161 fps=231 q=-1.0 Lsize=   20382kB time=00:00:48.00 bitrate=3478.6kbits/s speed=9.56x
video:20131kB audio:230kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.101893%
[libx264 @ 0000021440115c80] frame I:5     Avg QP:24.11  size: 68270
[libx264 @ 0000021440115c80] frame P:324   Avg QP:26.47  size: 31484
[libx264 @ 0000021440115c80] frame B:832   Avg QP:29.51  size: 12106
[libx264 @ 0000021440115c80] consecutive B-frames:  2.4%  4.0%  6.5% 87.2%
[libx264 @ 0000021440115c80] mb I  I16..4: 16.4% 29.9% 53.7%
[libx264 @ 0000021440115c80] mb P  I16..4:  7.8% 13.2% 11.2%  P16..4: 36.3% 17.7%  9.7%  0.0%  0.0%    skip: 4.2%
[libx264 @ 0000021440115c80] mb B  I16..4:  2.2%  3.4%  1.3%  B16..8: 44.0% 14.5%  4.9%  direct: 8.3%  skip:21.3%  L0:49.2% L1:41.8% BI: 9.0%
[libx264 @ 0000021440115c80] 8x8 transform intra:43.6% inter:46.3%
[libx264 @ 0000021440115c80] coded y,uvDC,uvAC intra: 75.5% 63.1% 16.4% inter: 36.0% 41.3% 7.4%
[libx264 @ 0000021440115c80] i16 v,h,dc,p: 27% 38% 16% 20%
[libx264 @ 0000021440115c80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 23% 30%  7%  4%  3%  6%  5%  7%
[libx264 @ 0000021440115c80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 34% 12%  4%  4%  3%  6%  3%  6%
[libx264 @ 0000021440115c80] i8c dc,h,v,p: 49% 26% 21%  4%
[libx264 @ 0000021440115c80] Weighted P-Frames: Y:0.6% UV:0.6%
[libx264 @ 0000021440115c80] ref P L0: 54.2% 17.0% 19.2%  9.5%  0.1%
[libx264 @ 0000021440115c80] ref B L0: 84.7% 12.4%  2.8%
[libx264 @ 0000021440115c80] ref B L1: 94.6%  5.4%
[libx264 @ 0000021440115c80] kb/s:3551.05
[aac @ 0000021440118640] Qavg: 58278.074

我画了黑色矩形来隐藏盘子。

我究竟做错了什么?

答案1

有两个问题:

1) 首先,如果未指定,ffmpeg 将自动设置比特率或质量参数。对于mpeg4,该比特率将为200 kbps。对于 1995 年的 VCD 上限来说还行,但对于今天的标准来说不行。设置足够高的比特率,例如-b:v 1500k,或质量因子-q:v 3

2) 其次,源视频是隔行扫描(锯齿状线条),如原始静止图像中所示。要进行去隔行扫描,请使用去隔行扫描滤镜,例如yadif

因此,完整命令如下

ffmpeg -i input.AVI -vf yadif -vcodec mpeg4 -q:v 3 output.mp4

相关内容