简体   繁体   English

ffmpeg - 如何估计 h264 视频目标大小的 CRF

[英]ffmpeg - How to estimate CRF for h264 video target size

According to the x264 encode documentation , in the CRF topic, it is informed that for every 6 additional points, the file size is reduced by approximately 50%.根据x264 编码文档,在 CRF 主题中,告知每增加 6 个点,文件大小将减少大约 50%。

From this statement, it is assumed that the CRF has an exponential influence in reducing the final size of the video.从这个陈述中,假设 CRF 在减小视频的最终大小方面具有指数影响。 But what is the exponential ratio?但是指数比是多少?

I wouldn't want to use CRF18 with max-rate adjusted to reach a final size, as maxrate damage complex video scenes more strongly, as bitrate reduction via max_rate is not uniform, but it hits the scenes that require the highest bitrate first.我不想使用 CRF18 并调整最大速率以达到最终大小,因为 maxrate 对复杂视频场景的破坏更大,因为通过 max_rate 降低比特率并不统一,但它首先会触及需要最高比特率的场景。

It is not possible to estimate a final video size without assuming the encode situation of the video to be converted.如果不假设要转换的视频的编码情况,则无法估计最终的视频大小。 If the initial file has not been reencoded at all, converting to CRF18 (imperceptible loss of quality to the eye) will already cause a large decrease in file size.如果初始文件根本没有重新编码,转换为 CRF18(肉眼无法察觉的质量损失)已经导致文件大小大幅减小。

To estimate final size of different CRF values, let's proceed with the assumption below: Initial file encoded in "CRF18 and present slow".为了估计不同 CRF 值的最终大小,让我们继续进行以下假设: 初始文件编码为“CRF18 并且呈现缓慢”。

By sliding dozens of conversions from this initial file, keeping the present slow and increasing the CRF by 0.2 points, it is possible to generate a data matrix to assess the influence of the final file size from changes in the CRF.通过从这个初始文件滑动几十个转换,保持当前缓慢并将 CRF 增加 0.2 个点,可以生成一个数据矩阵来评估最终文件大小对 CRF 变化的影响。

Having the data, just apply an exponential regression to find the factor that minimizes estimation error.有了数据,只需应用指数回归来找到最小化估计误差的因素。 The exponential factor I found in my tests was: 12.85% for each additional CRF point我在测试中发现的指数因子是:每增加一个 CRF 点 12.85%

So we can estimate that:所以我们可以估计:

size final = (size_crf18 * (1-0.1285)^(crf-18))最终尺寸 = (size_crf18 * (1-0.1285)^(crf-18))

And isolating the CRF variable, estimate the CRF needed to achieve an objective video size并隔离 CRF 变量,估计实现目标视频大小所需的 CRF

CRF needed = 18 + LOG(size_goal/size_crf18)/LOG(1-0,1285)需要 CRF = 18 + LOG(size_goal/size_crf18)/LOG(1-0,1285)

Example例子

  • Initial video with encode profile in CRF 18 preset slow, 3,500mb. CRF 18 预设慢速编码配置文件的初始视频,3,500mb。 Target to downsize to 2,000mb目标缩小到 2,000mb

Required CRF = 18+LOG(2000/3500)/LOG(1-0.1285) = 22.07所需的 CRF = 18+LOG(2000/3500)/LOG(1-0.1285) = 22.07

I recommend rounding to 1 decimal point and adding 0.2 points (lower 3% in final size) to minimize the estimation error exceeding the maximum desired size.我建议四舍五入到小数点后 1 位并添加 0.2 点(最终大小降低 3%),以尽量减少超出最大所需大小的估计误差。 Resulting in a required CRF22.3/slow to reduce a original file in h264/crf18/slow from 3500MB to 2000MB.导致所需的 CRF22.3/slow 将 h264/crf18/slow 中的原始文件从 3500MB 减少到 2000MB。

Final thoughts最后的想法

It is worth noting that the exponential ratio of 12.85% between CRF and file size seems adequate ONLY when all other flags are the same.值得注意的是,只有当所有其他标志都相同时,CRF 和文件大小之间的 12.85% 的指数比似乎才足够。 Changing other flags like present and maxrate can drastically influence the file size.更改诸如 present 和 maxrate 之类的其他标志会极大地影响文件大小。

As a future vision, it would be interesting to estimate the exponential ratio of the CRF considering different combinations of present between initial and final file, since an initial file in present ultrafast offers ample opportunity for size reduction if encoded in a preset slow.作为未来的愿景,考虑初始文件和最终文件之间存在的不同组合来估计 CRF 的指数比会很有趣,因为如果以预设的慢速编码,目前超快的初始文件提供了足够的减小大小的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM