压制玄学2021 - python版x265 ctu参数计算器

A@NAZOrip
A@NAZOrip 2021年02月28日
  • 在其它设备中阅读本文章
前言:

考虑到每次压视频都要算ctu大小,所以干脆丢给代码算吧(^▽^)
Encoding with x265 always takes time to consider ctu size, so let's just toss it into codes to do the work(^▽^)
由于本篇内容已经超出了本人的辣鸡编程水平,所以无法保证代码正常运行,有问题记得在评论区反馈哈~
Due to content complexity of this post has gone above this person's bad coding capability, you are not guaranteed with a working code, thus please return feedback at comment section below for problems~

代码:
def func_ctu(width,height):
    # define a y=mx+b line, pixel counts are on the y axis, 
    # then round up floats to speed up a bit
    ctu_rawsize = round((width*height+1396800)/59850)

    # 定义一条y=mx+b线段,像素数量列在y轴上,然后舍入去掉小数点来提一点速
    # b = 1396800, m = 59850, y = width × height

    if ctu_rawsize >= 64: 
        # eliminate value higher than or equal to max ctu size 
        # by giving answer directly
        # 对于超出或等于最大号的数就直接返回64
        return 64
    else:
        # and then find the nearest ctu value by...... 
        # define another func to finds minimum difference from 
        # list of all available ctu option values with ctu_rawsize
        # 然后找到最接近的ctu参数值,通过......定义另一套算式,
        # 找到与列表中所有可用ctu大小最接近的ctu_rawsize
        return sorted([16,32,64] , key = lambda x: abs(x-ctu_rawsize))[0]
特点:

若测算的ctu_rawsize在32和64之间,该代码会判断这个数更接近32还是64,从而避免脑筋急转弯(҂‾ ▵‾)︻デ═一 (˚▽˚'!)/
If calculated ctu_rawsize is inbetween 32 & 64, this code would check this number is actually closer to 32 or 64, thus prevents brain teasers

食用方法!

GUI参数 = print(func_ctu(视频宽,视频高))
CLI参数 = "--ctu "+str(func_ctu(视频宽,视频高))
API参数 = "ctu="+str(func_ctu(视频宽,视频高))

那么......啊,就这样...