如何解决将 MPEG-1 转码为 MPEG-H (H.265/HEVC)
使用 FFMPEG 文档中介绍的 2-pass 方法,将 MPEG-4 视频转码为 MPEG-H 以将大小减少一半而不损失可感知的质量相对容易。我一直在使用的方案是使用 bit_rate
从原始 MPEG-4 视频中提取 ffprobe
值,然后将该值乘以 4 / 10
。因此,新的较低值将由 -b:v
指定并成为结果 MPEG-H 视频的 bit_rate
值。这对于大多数视频都非常有效,不仅适用于 MPEG-4,而且适用于 QuickTime 和音频视频交错 (AVI)。
但是,现在我偶然发现了以这种方式转码 MPEG-1 视频的问题。不知何故,生成的 MPEG-H 视频比原始视频大得令人无法接受。 200MB 的原始视频很容易产生 1.5GB 的转码视频。当我寻找这种荒谬行为的原因时,我发现 MPEG-1 视频中宣传的 bit_rate
值不知何故也高得离谱。以下面两个视频为例(ffprobe
的输出):
164MB 15MB
[STREAM] [STREAM]
index=0 index=1
codec_name=mpeg4 codec_name=mpeg1video
codec_long_name=MPEG-4 part 2 codec_long_name=MPEG-1 video
profile=Simple Profile profile=unkNown
codec_type=video codec_type=video
codec_time_base=1/24 codec_time_base=1/25
codec_tag_string=mp4v codec_tag_string=[0][0][0][0]
codec_tag=0x7634706d codec_tag=0x0000
width=960 width=640
height=540 height=480
coded_width=960 coded_width=0
coded_height=540 coded_height=0
closed_captions=0 closed_captions=0
has_b_frames=0 has_b_frames=1
sample_aspect_ratio=1:1 sample_aspect_ratio=1:1
display_aspect_ratio=16:9 display_aspect_ratio=4:3
pix_fmt=yuv420p pix_fmt=yuv420p
level=1 level=-99
color_range=unkNown color_range=tv
color_space=unkNown color_space=unkNown
color_transfer=unkNown color_transfer=unkNown
color_primaries=unkNown color_primaries=unkNown
chroma_location=left chroma_location=center
field_order=unkNown field_order=unkNown
timecode=N/A timecode=N/A
refs=1 refs=1
quarter_sample=false
divx_packed=false
id=N/A id=0x1e0
r_frame_rate=24/1 r_frame_rate=25/1
avg_frame_rate=24/1 avg_frame_rate=25/1
time_base=1/24 time_base=1/90000
start_pts=0 start_pts=9900
start_time=0.000000 start_time=0.110000
duration_ts=7451 duration_ts=3690000
duration=310.458333 duration=41.000000
bit_rate=4096346 bit_rate=104857200
max_bit_rate=9000000 max_bit_rate=N/A
bits_per_raw_sample=N/A bits_per_raw_sample=N/A
nb_frames=7451 nb_frames=N/A
nb_read_frames=N/A nb_read_frames=N/A
nb_read_packets=N/A nb_read_packets=N/A
disPOSITION:default=1 disPOSITION:default=0
disPOSITION:dub=0 disPOSITION:dub=0
disPOSITION:original=0 disPOSITION:original=0
disPOSITION:comment=0 disPOSITION:comment=0
disPOSITION:lyrics=0 disPOSITION:lyrics=0
disPOSITION:karaoke=0 disPOSITION:karaoke=0
disPOSITION:forced=0 disPOSITION:forced=0
disPOSITION:hearing_impaired=0 disPOSITION:hearing_impaired=0
disPOSITION:visual_impaired=0 disPOSITION:visual_impaired=0
disPOSITION:clean_effects=0 disPOSITION:clean_effects=0
disPOSITION:attached_pic=0 disPOSITION:attached_pic=0
disPOSITION:timed_thumbnails=0 disPOSITION:timed_thumbnails=0
[/STREAM] [/STREAM]
显然,MPEG-4 视频比 MPEG-1 大 11 倍,但同时 MPEG-4 视频比 MPEG-1 宣传的比特率低 100000000。而且由于我的算法没有考虑其他任何东西来计算最终比特率,这就是问题本身的原因。现在我试图查看其他一些字段值以寻找可能还应该将其他内容包含在等式中的提示,我的怀疑在于以下几点:
time_base=1/24 time_base=1/90000
start_pts=0 start_pts=9900
start_time=0.000000 start_time=0.110000
duration_ts=7451 duration_ts=3690000
duration=310.458333 duration=41.000000
我不是 MPEG 方面的专家,而且文档在这些方面的信息并不多,我可以从中推导出一些数学知识,或者以其他方式将它们与以有意义的方式解决我的问题联系起来。有经验的可以帮忙吗?
解决方法
通过搜索网络,我发现 104857200
的比特率值是某种问题的迹象,可能与元数据有关。可以搜索ffmpeg
和104857 kb/s
关键字。因此,正如我的问题中已经提出的那样,这个值根本不能被认真对待。幸运的是,FORMAT
部分还包含文件的 bit_rate
,如下所示:
ffprobe -v error -show_entries format=bit_rate -of default=noprint_wrappers=1:nokey=1 <video-file>
在 MPEG-1 的情况下,此 bit_rate
值仅与视频流所需的比特率完全对应(是的,其中不包含音频流很重要)。例如,主题 MPEG-1 的值为 2914159
。
因此,将视频转码为 MPEG-H 的算法现在只是测试
的返回值是否ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 <video-file>
等于mpeg1video
,如果是,则从bit_rate
部分而不是视频FORMAT
部分进行分支检索STREAM
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。