为什么使用 ffmpeg 制作的视频文件 (x264) 的比特率比我在 Handbrake 中使用相同设置重新编码时要高得多?

为什么使用 ffmpeg 制作的视频文件 (x264) 的比特率比我在 Handbrake 中使用相同设置重新编码时要高得多?

我是 ffmpeg 新手,正在将每 10 秒拍摄的一系列 .png 图像转换为缩时视频。这些图像被命名为 pic1.png、pic2.png 等。

为此,我使用以下 ffmpeg 命令:

ffmpeg -i pic%d.png -c:v libx264 -preset veryfast -pix_fmt yuv420p -r 30 -crf 18 -vf "setpts=.2*PTS" output.mp4

它可以按预期工作,但是 7 秒长的输出视频具有 86 Mbit 的极高比特率。

Mediainfo 输出:

General
Complete name                            : Q:\ProxmoxOMV3\OpenCameraTablet\output.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 69.9 MiB
Duration                                 : 6 s 800 ms
Overall bit rate                         : 86.3 Mb/s
Frame rate                               : 30.000 FPS
Writing application                      : Lavf58.45.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 6 s 800 ms
Bit rate                                 : 86.3 Mb/s
Width                                    : 3 264 pixels
Height                                   : 1 824 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.483
Stream size                              : 69.9 MiB (100%)
Writing library                          : x264 core 160 r3011 cde9a93
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=2 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=3 / lookahead_threads=1 / 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=1 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=10 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

当我使用具有类似编码设置的 Handbrake 重新编码该输出视频时,它输出更合理的 21Mbit 比特率:

General
Complete name                            : C:\Users\Marko\Videos\Output.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (mp42/iso2/avc1/mp41)
File size                                : 17.3 MiB
Duration                                 : 6 s 800 ms
Overall bit rate                         : 21.3 Mb/s
Frame rate                               : 30.000 FPS
Encoded date                             : 2023-04-11 18:18:45 UTC
Tagged date                              : 2023-04-11 18:18:45 UTC
Writing application                      : HandBrake 1.6.1 2023012300

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L4
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 6 s 800 ms
Bit rate                                 : 21.3 Mb/s
Width                                    : 3 264 pixels
Height                                   : 1 824 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 30.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.119
Stream size                              : 17.3 MiB (100%)
Writing library                          : x264 core 164 r3100 ed0f7a6
Encoding settings                        : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=2 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=3 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=0 / weightp=1 / keyint=300 / keyint_min=30 / scenecut=40 / intra_refresh=0 / rc_lookahead=10 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=20000 / vbv_bufsize=25000 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Encoded date                             : 2023-04-11 18:18:45 UTC
Tagged date                              : 2023-04-11 18:18:45 UTC
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : avcC

有人能解释一下输出大小的差异吗?在这两种情况下,我都使用 CRF18、3264x1824 分辨率(与输入的 .png 图像相同)和“veryfast”预设。我确实看到了 mediainfo 输出中的一些差异。但我还不够熟练,无法理解它。

手刹‘活动日志’:

HandBrake 1.6.1 (2023012300)
OS: Microsoft Windows NT 10.0.19045.0
CPU: Intel(R) Core(TM)2 Duo CPU     P9400  @ 2.40GHz
Ram: 3983 MB, 
GPU Information:
  Mobile Intel(R) 4 Series Express Chipset Family (Microsoft Corporation - WDDM 1.1) - 8.15.10.2702
  Mobile Intel(R) 4 Series Express Chipset Family (Microsoft Corporation - WDDM 1.1) - 8.15.10.2702
Screen: 1680x1050
Temp Dir: C:\Users\Marko\AppData\Local\Temp\
Install Dir: C:\Program Files\HandBrake\
Data Dir: C:\Users\Marko\AppData\Roaming\HandBrake
[21:01:26] base preset: Fast 1080p30 (Modified)
[21:01:26] hb_init: starting libhb thread
[21:01:26] Starting work at: Tue Apr 11 21:01:26 2023
[21:01:26] 1 job(s) to process
[21:01:26] json job:
{
  "Audio": {
    "AudioList": [],
    "CopyMask": [
      "copy:aac"
    ]
  },
  "Destination": {
    "ChapterList": [
      {
        "Name": "Chapter 1"
      }
    ],
    "ChapterMarkers": true,
    "AlignAVStart": true,
    "File": "C:\\Users\\Marko\\Videos\\Output(1).mp4",
    "Mp4Options": {
      "IpodAtom": false,
      "Mp4Optimize": true
    },
    "Mux": "av_mp4"
  },
  "Filters": {
    "FilterList": [
      {
        "ID": 14,
        "Settings": {
          "crop-bottom": "0",
          "crop-left": "0",
          "crop-right": "0",
          "crop-top": "0",
          "height": "1824",
          "width": "3264"
        }
      },
      {
        "ID": 7,
        "Settings": {
          "mode": "1",
          "rate": "27000000/900000"
        }
      }
    ]
  },
  "PAR": {
    "Num": 1,
    "Den": 1
  },
  "Metadata": {},
  "SequenceID": 0,
  "Source": {
    "Angle": 1,
    "Range": {
      "Type": "chapter",
      "Start": 1,
      "End": 1
    },
    "Title": 1,
    "Path": "Q:\\ProxmoxOMV3\\OpenCameraTablet\\output.mp4"
  },
  "Subtitle": {
    "Search": {
      "Burn": true,
      "Default": false,
      "Enable": true,
      "Forced": true
    },
    "SubtitleList": []
  },
  "Video": {
    "Encoder": "x264",
    "Level": "4.0",
    "TwoPass": false,
    "Turbo": false,
    "ColorMatrixCode": 0,
    "Options": "",
    "Preset": "veryfast",
    "Profile": "main",
    "Quality": 18,
    "QSV": {
      "Decode": false
    },
    "HardwareDecode": 0
  }
}
[21:01:26] CPU: Intel(R) Core(TM)2 Duo CPU     P9400  @ 2.40GHz
[21:01:26]  - logical processor count: 2
[21:01:26] Intel Quick Sync Video support: no
[21:01:26] hb_scan: path=Q:\ProxmoxOMV3\OpenCameraTablet\output.mp4, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
src/libbluray/disc/disc.c:333: failed opening UDF image Q:\ProxmoxOMV3\OpenCameraTablet\output.mp4
src/libbluray/disc/disc.c:437: error opening file BDMV\index.bdmv
src/libbluray/disc/disc.c:437: error opening file BDMV\BACKUP\index.bdmv
[21:01:26] bd: not a bd - trying as a stream/file instead
libdvdread: DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav: vm: vm: failed to read VIDEO_TS.IFO
[21:01:26] dvd: not a dvd - trying as a stream/file instead
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Q:\ProxmoxOMV3\OpenCameraTablet\output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:06.80, start: 0.000000, bitrate: 86282 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 3264x1824, 86277 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
[21:01:26] scan: decoding previews for title 1
[21:01:33] scan: 10 previews, 3264x1824, 30.000 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
[21:01:33] libhb: scan thread found 1 valid title(s)
[21:01:33] Skipping subtitle scan.  No suitable subtitle tracks.
[21:01:33] Starting Task: Encoding Pass
[21:01:33] Skipping crop/scale filter
[21:01:33] work: only 1 chapter, disabling chapter markers
[21:01:33] job configuration:
[21:01:33]  * source
[21:01:33]    + Q:\ProxmoxOMV3\OpenCameraTablet\output.mp4
[21:01:33]    + title 1, chapter(s) 1 to 1
[21:01:33]    + container: mov,mp4,m4a,3gp,3g2,mj2
[21:01:33]    + data rate: 86282 kbps
[21:01:33]  * destination
[21:01:33]    + C:\Users\Marko\Videos\Output(1).mp4
[21:01:33]    + container: MPEG-4 (libavformat)
[21:01:33]      + optimized for HTTP streaming (fast start)
[21:01:33]      + align initial A/V stream timestamps
[21:01:33]  * video track
[21:01:33]    + decoder: h264 8-bit (yuv420p)
[21:01:33]      + bitrate 86277 kbps
[21:01:33]    + filter
[21:01:33]      + Framerate Shaper (mode=1:rate=27000000/900000)
[21:01:33]        + frame rate: 30.000 fps -> constant 30.000 fps
[21:01:33]    + Output geometry
[21:01:33]      + storage dimensions: 3264 x 1824
[21:01:33]      + pixel aspect ratio: 1 : 1
[21:01:33]      + display dimensions: 3264 x 1824
[21:01:33]    + encoder: H.264 (libx264)
[21:01:33]      + preset:  veryfast
[21:01:33]      + profile: main
[21:01:33]      + level:   4.0
[21:01:33]      + quality: 18.00 (RF)
[21:01:33]      + color profile: 1-1-1
[21:01:33]      + chroma location: left
[21:01:33] sync: expecting 204 video frames
[21:01:33] encx264: min-keyint: 30, keyint: 300
[21:01:33] encx264: encoding at constant RF 18.000000
[21:01:33] apply_h264_level [warning]: frame size (3264x1824, 23256 macroblocks) too high for level 4.0 (max. 8192 macroblocks)
[21:01:33] encx264: unparsed options: level=4.0:ref=1:bframes=0:8x8dct=0:weightp=1:subme=2:mixed-refs=0:trellis=0:vbv-bufsize=25000:vbv-maxrate=20000:rc-lookahead=10
x264 [info]: using SAR=1/1
x264 [warning]: frame MB size (204x114) > level limit (8192)
x264 [warning]: MB rate (697680) > level limit (245760)
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64 UnalignedStack
x264 [info]: profile Main, level 4.0, 4:2:0, 8-bit
[21:01:35] sync: first pts video is 0
[21:01:35] sync: "Chapter 1" (1) at frame 1 time 0
[21:02:13] reader: done. 1 scr changes
[21:02:31] work: average encoding speed for job is 3.922514 fps
[21:02:32] vfr: 204 frames output, 0 dropped and 0 duped for CFR/PFR
[21:02:32] vfr: lost time: 0 (0 frames)
[21:02:32] vfr: gained time: 0 (0 frames) (0 not accounted for)
[21:02:32] h264-decoder done: 204 frames, 0 decoder errors
[21:02:32] sync: got 204 frames, 204 expected
[21:02:32] sync: framerate min 30.000 fps, max 30.000 fps, avg 30.000 fps
x264 [info]: frame I:2     Avg QP:24.17  size:414991
x264 [info]: frame P:202   Avg QP:26.65  size: 85418
x264 [info]: mb I  I16..4: 31.4%  0.0% 68.6%
x264 [info]: mb P  I16..4: 12.1%  0.0%  1.4%  P16..4: 39.4% 14.8%  6.2%  0.0%  0.0%    skip:26.1%
x264 [info]: coded y,uvDC,uvAC intra: 22.7% 13.6% 0.1% inter: 23.9% 4.6% 0.0%
x264 [info]: i16 v,h,dc,p: 34% 26% 29% 11%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 20% 24%  4%  9%  6%  7%  5%  7%
x264 [info]: i8c dc,h,v,p: 73% 13% 12%  1%
x264 [info]: Weighted P-Frames: Y:23.8% UV:0.5%
x264 [info]: kb/s:21275.90
[21:02:32] mux: track 0, 204 frames, 18084437 bytes, 21172.02 kbps, fifo 128
[21:02:32] Finished work at: Tue Apr 11 21:02:32 2023
[21:02:32] libhb: work result = 0
Job Completed!

相关内容