问题
我有一个 MKV 文件,其中有 1 个视频和 1 个字幕流,我想对字幕流进行硬编码并输出 MP4 文件。
可以找到示例文件、图像和结果这里。
mediainfo
General
Unique ID : 169861028457722525578038513971806461765 (0x7FCA0B4ABC222F3850F6CF659051DF45)
Format : Matroska
Format version : Version 4
File size : 1.97 MiB
Duration : 8 s 426 ms
Overall bit rate : 1 959 kb/s
Encoded date : UTC 2022-12-11 19:29:00
Writing application : mkvmerge v65.0.0 ('Too Much') 64-bit
Writing library : libebml v1.4.2 + libmatroska v1.6.4
Attachments : GENTIUMBASIC.TTF
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High 10@L5
Format settings : CABAC / 8 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 8 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 8 s 426 ms
Bit rate : 1 694 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (23976/1000) FPS
Original frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.034
Stream size : 1.70 MiB (86%)
Default : Yes
Forced : No
Color range : Limited
Matrix coefficients : BT.709
Text
ID : 2
Format : ASS
Codec ID : S_TEXT/ASS
Codec ID/Info : Advanced Sub Station Alpha
Duration : 1 s 540 ms
Bit rate : 4 815 b/s
Frame rate : 3.247 FPS
Count of elements : 5
Compression mode : Lossless
Stream size : 927 Bytes (0%)
Default : Yes
Forced : No
通常我在对字幕进行硬编码时执行以下操作:
ffmpeg -i "original.mkv" -filter_complex "subtitles='original.mkv':si=0" -pix_fmt yuv420p -c:v libx264 -crf 18 "output.mp4"
但这次它给了我一个不理想的结果:
我希望看到的是期望结果,与我在 Aegisub 中看到的类似:
此时,我猜测这可能与不同的色彩空间或像素格式有关,以及/或者与 ffmpeg 一起使用不正确。由于我对此不太熟悉,因此我寻求帮助。
补充笔记
我使用 FFmpeg 和 Handbrake 对其进行了硬编码,使用类似设置进行硬编码时,两者给出的结果不同。由于 Handbrake 在后台使用 FFmpeg,因此我并不期望字幕的结果会有所不同,但显然 Handbrake 给出了所需的结果。
手刹
关闭所有过滤器。
日志
HandBrake 1.5.1 (2022011000)
OS: Microsoft Windows NT 10.0.19044.0
CPU: AMD Ryzen 9 3900X 12-Core Processor
Ram: 32693 MB,
GPU Information:
NVIDIA GeForce RTX 3060 Ti - 31.0.15.2225
Screen: 1920x1080
Temp Dir: C:\Users\AppData\Local\Temp\
Install Dir: C:\Program Files\HandBrake\
Data Dir: C:\Users\AppData\Roaming\HandBrake
-------------------------------------------
# Starting Encode ...
[20:39:10] base preset: Fast 1080p30 (Modified)
[20:39:10] Remote Process started with Process ID: 31324 using port: 8037. Max Allowed Instances: 1
[20:39:10] Worker: Starting HandBrake Engine ...
[20:39:10] Worker: Starting Web Server on port 8037 ...
[20:39:11] Worker: Disconnected worker monitoring enabled!
[20:39:11] Compile-time hardening features are enabled
[20:39:11] hb_init: starting libhb thread
[20:39:11] Starting work at: Sun Dec 11 20:39:11 2022
[20:39:11] 1 job(s) to process
[20:39:11] json job:
{
"Audio": {
"AudioList": [],
"CopyMask": [
"copy:aac",
"copy:ac3",
"copy:dtshd",
"copy:dts",
"copy:eac3",
"copy:flac",
"copy:mp3",
"copy:truehd",
"copy:mp2"
],
"FallbackEncoder": "ac3"
},
"Destination": {
"ChapterList": [],
"ChapterMarkers": false,
"AlignAVStart": false,
"File": "C:\\Users\\Desktop\\handbrake-result.mp4",
"Mp4Options": {
"IpodAtom": false,
"Mp4Optimize": false
},
"Mux": "av_mp4"
},
"Filters": {
"FilterList": [
{
"ID": 13,
"Settings": {
"crop-bottom": "0",
"crop-left": "0",
"crop-right": "0",
"crop-top": "0",
"height": "1080",
"width": "1920"
}
},
{
"ID": 6,
"Settings": {
"mode": "1"
}
}
]
},
"PAR": {
"Num": 1,
"Den": 1
},
"Metadata": {},
"SequenceID": 0,
"Source": {
"Angle": 1,
"Range": {
"Type": "chapter",
"Start": 1,
"End": 1
},
"Title": 1,
"Path": "C:\\Users\\Desktop\\original.mkv"
},
"Subtitle": {
"Search": {
"Burn": false,
"Default": false,
"Enable": false,
"Forced": false
},
"SubtitleList": [
{
"Burn": true,
"Default": false,
"Forced": false,
"ID": 1,
"Offset": 0,
"Track": 0
}
]
},
"Video": {
"Encoder": "x264",
"Level": "5.0",
"TwoPass": false,
"Turbo": false,
"ColorMatrixCode": 0,
"Options": "",
"Preset": "fast",
"Profile": "high",
"Quality": 22,
"QSV": {
"Decode": false
}
}
}
[20:39:11] CPU:
[20:39:11] - logical processor count: 24
[20:39:11] Intel Quick Sync Video support: no
[20:39:11] hb_scan: path=C:\Users\Desktop\original.mkv, title_index=1
udfread ERROR: ECMA 167 Volume Recognition failed
src/libbluray/disc/disc.c:333: failed opening UDF image C:\Users\Desktop\original.mkv
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
src/libbluray/bluray.c:2646: nav_get_title_list(C:\Users\Desktop\original.mkv\) failed
[20:39:11] bd: not a bd - trying as a stream/file instead
libdvdread: Encrypted DVD support unavailable.
libdvdread: Canlibdvdread: DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
't open file VIDEO_TS.IFO.
libdvdnav: vm: vm: failed to read VIDEO_TS.IFO
[20:39:11] dvd: not a dvd - trying as a stream/file instead
Input #0, matroska,webm, from 'C:\Users\Desktop\original.mkv':
Metadata:
encoder : libebml v1.4.2 + libmatroska v1.6.4
creation_time : 2022-12-11T19:29:00.000000Z
Duration: 00:00:08.43, start: 0.000000, bitrate: 1958 kb/s
Stream #0:0: Video: h264 (High 10), yuv420p10le(tv, bt709/unknown/unknown, progressive), 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
BPS : 1693698
DURATION : 00:00:08.426000000
NUMBER_OF_FRAMES: 202
NUMBER_OF_BYTES : 1783888
_STATISTICS_WRITING_APP: mkvmerge v65.0.0 ('Too Much') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2022-12-11 19:29:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1: Subtitle: ass (default)
Metadata:
BPS : 4815
DURATION : 00:00:01.540000000
NUMBER_OF_FRAMES: 5
NUMBER_OF_BYTES : 927
_STATISTICS_WRITING_APP: mkvmerge v65.0.0 ('Too Much') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2022-12-11 19:29:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2: Attachment: none
Metadata:
filename : GENTIUMBASIC.TTF
mimetype : font/ttf
[20:39:11] scan: decoding previews for title 1
[20:39:11] scan: 10 previews, 1920x1080, 23.976 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1, color profile: 1-1-1, chroma location: left
[20:39:11] libhb: scan thread found 1 valid title(s)
[20:39:11] Starting Task: Encoding Pass
[20:39:11] Skipping crop/scale filter
[20:39:11] [ass] libass API version: 0x1502000
[20:39:11] [ass] libass source: tarball: 0.15.2
[20:39:11] [ass] Shaper: FriBidi 1.0.11 (SIMPLE) HarfBuzz-ng 3.1.2 (COMPLEX)
[20:39:11] [ass] Using font provider directwrite (with GDI)
[20:39:11] job configuration:
[20:39:11] * source
[20:39:11] + C:\Users\Desktop\original.mkv
[20:39:11] + title 1, chapter(s) 1 to 1
[20:39:11] + container: matroska,webm
[20:39:11] + data rate: 1958 kbps
[20:39:11] * destination
[20:39:11] + C:\Users\Desktop\handbrake-result.mp4
[20:39:11] + container: MPEG-4 (libavformat)
[20:39:11] * video track
[20:39:11] + decoder: h264 10-bit (yuv420p10le)
[20:39:11] + filters
[20:39:11] + Framerate Shaper (mode=1)
[20:39:11] + frame rate: 23.976 fps -> constant 23.976 fps
[20:39:11] + Subtitle renderer ()
[20:39:11] + Format (format=yuv420p)
[20:39:11] + Output geometry
[20:39:11] + storage dimensions: 1920 x 1080
[20:39:11] + pixel aspect ratio: 1 : 1
[20:39:11] + display dimensions: 1920 x 1080
[20:39:11] + encoder: H.264 (libx264)
[20:39:11] + preset: fast
[20:39:11] + profile: high
[20:39:11] + level: 5.0
[20:39:11] + quality: 22.00 (RF)
[20:39:11] + color profile: 1-1-1
[20:39:11] + chroma location: left
[20:39:11] * subtitle track 1, Unknown [SSA] (track 0, id 0x1, Text) -> Render/Burn-in
[20:39:11] sync: expecting 202 video frames
[20:39:11] encx264: min-keyint: 24, keyint: 240
[20:39:11] encx264: encoding at constant RF 22.000000
[20:39:11] encx264: unparsed options: level=5.0:ref=2:weightp=1:subme=6:vbv-bufsize=168750:vbv-maxrate=168750:rc-lookahead=30
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x264 [info]: profile High, level 5.0, 4:2:0, 8-bit
[20:39:11] sync: first pts video is 0
[20:39:11] sync: Chapter 1 at frame 1 time 0
[20:39:11] sync: first pts subtitle 0x1 is 110700
[20:39:12] [ass] fontselect: (Arial, 400, 0) -> ArialMT, 0, ArialMT
[20:39:12] [ass] fontselect: (Gentium Basic, 400, 0) -> GentiumBasic, 0, GentiumBasic
[20:39:12] reader: done. 1 scr changes
[20:39:13] work: average encoding speed for job is 0.000000 fps
[20:39:13] vfr: 202 frames output, 0 dropped and 0 duped for CFR/PFR
[20:39:13] vfr: lost time: 0 (0 frames)
[20:39:13] vfr: gained time: 0 (0 frames) (0 not accounted for)
[20:39:13] h264-decoder done: 202 frames, 0 decoder errors
[20:39:13] sync: got 202 frames, 202 expected
[20:39:13] sync: framerate min 23.976 fps, max 23.976 fps, avg 23.976 fps
x264 [info]: frame I:6 Avg QP:13.01 size:143206
x264 [info]: frame P:51 Avg QP:15.88 size: 2936
x264 [info]: frame B:145 Avg QP:18.37 size: 443
x264 [info]: consecutive B-frames: 3.5% 1.0% 4.5% 91.1%
x264 [info]: mb I I16..4: 18.3% 66.7% 15.0%
x264 [info]: mb P I16..4: 0.2% 0.7% 0.1% P16..4: 3.2% 1.0% 0.6% 0.0% 0.0% skip:94.0%
x264 [info]: mb B I16..4: 0.0% 0.4% 0.0% B16..8: 0.6% 0.1% 0.0% direct: 0.6% skip:98.3% L0:51.4% L1:42.6% BI: 6.0%
x264 [info]: 8x8 transform intra:68.7% inter:78.3%
x264 [info]: coded y,uvDC,uvAC intra: 64.1% 64.8% 55.3% inter: 0.5% 0.8% 0.0%
x264 [info]: i16 v,h,dc,p: 50% 32% 8% 10%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 35% 23% 3% 1% 1% 2% 2% 4%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 28% 5% 6% 5% 5% 6% 5% 5%
x264 [info]: i8c dc,h,v,p: 55% 22% 20% 4%
x264 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x264 [info]: ref P L0: 81.4% 18.6%
x264 [info]: ref B L0: 84.8% 15.2%
x264 [info]: ref B L1: 96.0% 4.0%
x264 [info]: kb/s:1019.07
[20:39:13] mux: track 0, 202 frames, 1072961 bytes, 1018.83 kbps, fifo 256
[20:39:13] Finished work at: Sun Dec 11 20:39:13 2022
[20:39:13] libhb: work result = 0
# Job Completed!
结果 mediainfo
General
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (mp42/iso2/avc1/mp41)
File size : 1.03 MiB
Duration : 8 s 426 ms
Overall bit rate : 1 023 kb/s
Encoded date : UTC 2022-12-11 19:39:11
Tagged date : UTC 2022-12-11 19:39:11
Writing application : HandBrake 1.5.1 2022011000
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L5
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 : 8 s 426 ms
Bit rate : 1 019 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 23.976 (24000/1001) FPS
Minimum frame rate : 23.974 FPS
Maximum frame rate : 23.981 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.020
Stream size : 1.02 MiB (100%)
Writing library : x264 core 164 r3065 ae03d92
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / 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=34 / lookahead_threads=5 / 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=240 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=22.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=168750 / vbv_bufsize=168750 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Encoded date : UTC 2022-12-11 19:39:11
Tagged date : UTC 2022-12-11 19:39:11
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
mdhd_Duration : 8425
Codec configuration box : avcC
视觉的
FFmpeg
日志
ffmpeg version 5.0.1-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.2.0 (Rev7, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
[matroska,webm @ 00000203f1dbb980] Could not find codec parameters for stream 2 (Attachment: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, matroska,webm, from 'original.mkv':
Metadata:
encoder : libebml v1.4.2 + libmatroska v1.6.4
creation_time : 2022-12-11T19:29:00.000000Z
Duration: 00:00:08.43, start: 0.000000, bitrate: 1958 kb/s
Stream #0:0: Video: h264 (High 10), yuv420p10le(tv, bt709/unknown/unknown, progressive), 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn (default)
Metadata:
BPS : 1693698
DURATION : 00:00:08.426000000
NUMBER_OF_FRAMES: 202
NUMBER_OF_BYTES : 1783888
_STATISTICS_WRITING_APP: mkvmerge v65.0.0 ('Too Much') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2022-12-11 19:29:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1: Subtitle: ass (default)
Metadata:
BPS : 4815
DURATION : 00:00:01.540000000
NUMBER_OF_FRAMES: 5
NUMBER_OF_BYTES : 927
_STATISTICS_WRITING_APP: mkvmerge v65.0.0 ('Too Much') 64-bit
_STATISTICS_WRITING_DATE_UTC: 2022-12-11 19:29:00
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2: Attachment: none
Metadata:
filename : GENTIUMBASIC.TTF
mimetype : font/ttf
[Parsed_subtitles_0 @ 00000203f1e54b00] libass API version: 0x1502002
[Parsed_subtitles_0 @ 00000203f1e54b00] libass source: commit: 0.15.2-69-gf664ced049394e2a5d4300ba526e206df73ec729
[Parsed_subtitles_0 @ 00000203f1e54b00] Shaper: FriBidi 1.0.11 (SIMPLE) HarfBuzz-ng 4.2.0 (COMPLEX)
[matroska,webm @ 00000203f2510c80] Could not find codec parameters for stream 2 (Attachment: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
[Parsed_subtitles_0 @ 00000203f1e54b00] Using font provider directwrite (with GDI)
Stream mapping:
Stream #0:0 (h264) -> subtitles:default
subtitles:default -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[Parsed_subtitles_0 @ 00000203f2088b80] libass API version: 0x1502002
[Parsed_subtitles_0 @ 00000203f2088b80] libass source: commit: 0.15.2-69-gf664ced049394e2a5d4300ba526e206df73ec729
[Parsed_subtitles_0 @ 00000203f2088b80] Shaper: FriBidi 1.0.11 (SIMPLE) HarfBuzz-ng 4.2.0 (COMPLEX)
[matroska,webm @ 00000203f1fdeac0] Could not find codec parameters for stream 2 (Attachment: none): unknown codec
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
[Parsed_subtitles_0 @ 00000203f2088b80] Using font provider directwrite (with GDI)
[libx264 @ 00000203f2973040] using SAR=1/1
[libx264 @ 00000203f2973040] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000203f2973040] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 00000203f2973040] 264 - core 164 r3094 bfc87b7 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - 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=34 lookahead_threads=5 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=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'ffmpeg-result.mp4':
Metadata:
encoder : Lavf59.16.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/unknown, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 24k tbn
Metadata:
encoder : Lavc59.18.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[Parsed_subtitles_0 @ 00000203f2088b80] fontselect: (Arial, 400, 0) -> ArialMT, 0, ArialMT
[Parsed_subtitles_0 @ 00000203f2088b80] fontselect: (Gentium Basic, 400, 0) -> GentiumBasic, 0, GentiumBasic
frame= 202 fps=158 q=-1.0 Lsize= 1748kB time=00:00:08.30 bitrate=1724.9kbits/s speed=6.47x
video:1744kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.185189%
[libx264 @ 00000203f2973040] frame I:6 Avg QP: 8.48 size:245788
[libx264 @ 00000203f2973040] frame P:51 Avg QP:12.66 size: 4628
[libx264 @ 00000203f2973040] frame B:145 Avg QP:17.59 size: 516
[libx264 @ 00000203f2973040] consecutive B-frames: 3.5% 1.0% 4.5% 91.1%
[libx264 @ 00000203f2973040] mb I I16..4: 25.7% 58.7% 15.7%
[libx264 @ 00000203f2973040] mb P I16..4: 0.1% 0.9% 0.2% P16..4: 3.0% 1.2% 0.8% 0.0% 0.0% skip:93.9%
[libx264 @ 00000203f2973040] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 2.6% 0.2% 0.0% direct: 0.0% skip:97.2% L0:42.9% L1:54.4% BI: 2.7%
[libx264 @ 00000203f2973040] 8x8 transform intra:60.1% inter:73.3%
[libx264 @ 00000203f2973040] coded y,uvDC,uvAC intra: 78.9% 79.0% 76.4% inter: 0.6% 0.6% 0.1%
[libx264 @ 00000203f2973040] i16 v,h,dc,p: 45% 29% 18% 8%
[libx264 @ 00000203f2973040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 35% 21% 3% 2% 1% 2% 2% 5%
[libx264 @ 00000203f2973040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 27% 6% 6% 6% 5% 6% 6% 6%
[libx264 @ 00000203f2973040] i8c dc,h,v,p: 50% 24% 22% 4%
[libx264 @ 00000203f2973040] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000203f2973040] ref P L0: 80.0% 3.9% 11.0% 5.1%
[libx264 @ 00000203f2973040] ref B L0: 83.7% 14.4% 1.9%
[libx264 @ 00000203f2973040] ref B L1: 92.4% 7.6%
[libx264 @ 00000203f2973040] kb/s:1695.50
结果 mediainfo
General
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 1.71 MiB
Duration : 8 s 426 ms
Overall bit rate : 1 699 kb/s
Writing application : Lavf59.16.100
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
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 : 8 s 426 ms
Bit rate : 1 696 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.034
Stream size : 1.70 MiB (100%)
Writing library : x264 core 164 r3094 bfc87b7
Encoding settings : 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=34 / lookahead_threads=5 / 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=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Color range : Limited
Matrix coefficients : BT.709
Codec configuration box : avcC
视觉的
字幕
嵌入的 ASS 字幕包含条目YCbCr Matrix: TV.709
,因此我认为它对应于视频的BT.709
色彩空间。
我尝试过不同的值pix_fmt
,或者-filter:s
添加colorspaces
过滤器,但到目前为止还没有运气。
由于 mediainfo 中似乎没有明显的差异,我有点搞不清楚是什么导致了颜色不正确。任何帮助都非常感谢。
测试过的 FFmpeg 版本
5.0.1 on Windows 10
5.1.2 on Ubuntu 22.10
答案1
为了解决这个问题,我们可能会将视频转换为BT.601颜色标准,添加字幕并将结果转换为BT.709颜色标准:
ffmpeg -y -i "original.mkv" -filter_complex "scale=in_color_matrix=bt709:out_color_matrix=bt601,subtitles='original.mkv':si=0,scale=in_color_matrix=bt601:out_color_matrix=bt709" -pix_fmt yuv420p -c:v libx264 -crf 18 "output.mp4"
该问题可能与原始视频采用“High 10@L5”配置文件编码、位深度为 10 位有关。
我不知道字幕是否有定义的色彩标准(如 BT.709 有限范围),但似乎 FFmpeg 对字幕使用 BT.601 有限范围色彩标准。
似乎字幕过滤器也没有为绘制的字幕选择 BT.709 颜色标准的选项。
我建议的解决方案是:
将每个视频帧从 BT.709 转换为 BT.601 色彩标准:
scale=in_color_matrix=bt709:out_color_matrix=bt601
在“BT.601 彩色”框架上添加(绘制)字幕:
subtitles='original.mkv'
重新编码之前将色彩标准从 BT.601 转换回 BT.709 标准:
scale=in_color_matrix=bt601:out_color_matrix=bt709
请注意,从 10 位深度转换为 8 位深度时,我们会丢失一些颜色信息,但我找不到解决方案。
答案2
在@Rotem 的解决方案之后,我开始考虑另一种解决方案,产生相同的结果,而无需使用颜色矩阵进行缩放。
但是,这需要使用 Aegisub 修改字幕文件并在现有 MKV 文件中重新混合/替换新字幕文件的其他步骤。
埃吉苏布
我已指出字幕文件有一个YCbCr Matrix: TV.709
条目集。虽然这与视频的色彩空间相匹配,但我还是尝试更改它。
- 在
File
>中Properties
,YCbCr Matrix
从更改TV.709
为TV.601
。 - 在
Subtitle
>Resample resolution
Source Resolution
使用YCbCr Matrix: TV.709
Destination Resolution
使用YCbCr Matrix: TV.601
- 单击
Ok
并保存新的字幕文件。
MKVToolnix
将新的字幕文件重新混合到现有的 MKV 文件中。
最初在 VLC/MPC-HC 中看到它时,它看起来有点奇怪(使用 Windows 截图工具截取的屏幕截图):
但使用 VLC 的内置截图功能显示出更有希望的前景:
FFmpeg
运行原始命令对新文件进行硬编码。
ffmpeg -i "original-v2.mkv" -filter_complex "subtitles='original-v2.mkv':si=0" -pix_fmt yuv420p -c:v libx264 -crf 18 "output-v2.mp4"
这看起来几乎与 Rotem 的结果相同,只是颜色矩阵进行了缩放。我说几乎从视觉上看,重新缩放后的图看起来稍微暗一些(红色)。
下面比较两个结果的媒体信息,除了比特率/文件大小外几乎相同。
ffmpeg scale
General
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 1.55 MiB
Duration : 8 s 426 ms
Overall bit rate : 1 548 kb/s
Writing application : Lavf59.16.100
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
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 : 8 s 426 ms
Bit rate : 1 545 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.031
Stream size : 1.55 MiB (100%)
Writing library : x264 core 164 r3094 bfc87b7
Encoding settings : 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=34 / lookahead_threads=5 / 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=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Color range : Limited
Matrix coefficients : BT.709
Codec configuration box : avcC
aegisub-mkvtoolnix-ffmpeg
General
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 1.70 MiB
Duration : 8 s 426 ms
Overall bit rate : 1 696 kb/s
Writing application : Lavf59.16.100
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
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 : 8 s 426 ms
Bit rate : 1 693 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.034
Stream size : 1.70 MiB (100%)
Writing library : x264 core 164 r3094 bfc87b7
Encoding settings : 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=34 / lookahead_threads=5 / 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=23 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Color range : Limited
Matrix coefficients : BT.709
Codec configuration box : avcC
可以找到所有结果这里。
我的结论是,这样就不需要使用 ffmpeg 进行缩放,因此性能更好,但需要手动更改字幕文件属性(和重新采样)和重新混合,因此仍然很耗时。
虽然这两种解决方案似乎都有效,但我不确定其中一种是否是适用于多种用例的实际可行解决方案,因为它们都需要执行密集的操作。
我很想有一个不需要这种缩放并且能够“神奇地”自己解决这个问题的通用解决方案,但我只是无法弄清楚这是 1) FFmpeg 中的错误,2) 与字幕渲染器本身有关,3) 从未实现,4) 完全不同的东西。