搜索 社区服务 统计排行 帮助
  • 3288阅读
  • 2回复

H.264级别(Level)计算器(JavaScript网页版)

楼层直达
级别: 新手上路
注册时间:
2011-11-17
在线时间:
7小时
发帖:
11
www.cnblogs.com/zyl910/archive/2011/12/12/h264_level_calculator.html

H.264级别(Level)计算器(JavaScript网页版)

  上回我们学会了怎么计算级别(H.264 级别(Level)、DPB 与 MaxDpbMbs 详解:http://www.cnblogs.com/zyl910/archive/2011/12/08/h264_level.html)。但是每次手工计算就太麻烦了,我们希望有一款工具能完成这些运算。最好该工具还能跨平台使用。
  在综合考虑上面的需求 和 开发难度性 后,我决定编写一个JavaScript网页程序。

  最终效果——


下载地址——
files.cnblogs.com/zyl910/h264_level_calculator.rar



作者:zyl910
出处:cnblogs.com/zyl910/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利

x264编码参数测试: 549335
级别: 骑士
注册时间:
2008-10-06
在线时间:
115小时
发帖:
319
只看该作者 1楼 发表于: 2011-12-13
  1. #!/bin/env python
  2. # coding: utf-8
  3. #****************************************************************************
  4. #  avc_refcalc.py 0.20
  5. #                                   written by Chikezun
  6. #  Reference literature:
  7. #    インプレス標準教科書シリーズ改訂版 H.264/AVC教科書
  8. #           著者:(監修)大久保 榮/(編者)角野 眞也、菊池 義浩、鈴木 輝彦
  9. #    http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC
  10. #    猫科研究所(http://www.up-cat.net/FrontPage.html)
  11. #         x264(vbv-maxrate,vbv-bufsize,profile,level),H.264(Profile/Level)
  12. #
  13. #****************************************************************************
  14. import sys
  15. import math
  16. def usage():
  17.     print "Usage: avc_refcalc.py [options]\n"
  18.     print "  -r, --resolution <string> :set 'width x height' ('1280x720')"
  19.     print "  -l, --level <string>      :set 'level' ('4.1')"
  20.     print "  -p, --profile <string>    :set 'profile' ('high')"
  21.     print "  -i, --interlaced          :specify interlaced mode (not specified)"
  22.     print "  -h, --help                :display this help and exit\n"
  23. def check_prof(pr, ip):
  24.     for i in ['baseline', 'main', 'high']:
  25.         if i == pr:
  26.             if i != 'baseline' or ip != 'interlaced':
  27.                 return i
  28.             else:
  29.                 print "ERROR : baseline cannot accept interlaced."
  30.     print "ERROR : invalid profile setting.\n"
  31.     usage()
  32.     sys.exit()
  33. def check_level(lv, ip, dic):
  34.     lvl = lv.replace('0','').replace('.','')
  35.     if dic.has_key(lvl):
  36.         if ip[0] != 'i' or dic.get(lvl)[0] == 'i':
  37.             return lvl
  38.         else:
  39.             print "ERROR : specified level cannot accept interlaced."
  40.     print "ERROR : invalid level value.\n"
  41.     usage()
  42.     sys.exit()
  43. def calc_mbs(w, h, ip):
  44.     mbh = int(math.ceil(float(w) / 16))
  45.     mbv = int(math.ceil(float(h) / 16))
  46.     if mbv % 2 == 1 and ip == 'interlaced':
  47.         mbv += 1
  48.     mbs = mbh * mbv
  49.     if mbs > 0:
  50.         return mbs
  51.     else:
  52.         print "ERROR : invalid resolution setting.\n"
  53.         usage()
  54.         sys.exit()
  55. def calc_vbv(lv, pr, dic):
  56.     vbvmax = dic.get(lv)[1]
  57.     vbvbuf = dic.get(lv)[2]
  58.     if pr == 'high':
  59.         return [int(vbvmax * 1.25), int(vbvbuf * 1.25)]
  60.     else:
  61.         return [vbvmax, vbvbuf]
  62. def calc_maxref(lv, mbs, dic):
  63.     ref = int(dic.get(lv)[3] / mbs)
  64.     if ref > 16:
  65.         ref = 16
  66.     if ref > 0:
  67.         return ref
  68.     else:
  69.         print "ERROR : resolution is too large to level.\n"
  70.         usage()
  71.         sys.exit()
  72. options = sys.argv
  73. len_opt = len(options)
  74. #set default values
  75. width  = 1280
  76. height = 720
  77. level  = '4.1'
  78. prof   = 'high'
  79. mode   = 'progressive'
  80. help   = 0
  81. #H.264/AVC level dictionary {level: [interlaced flag, MaxBR, MaxCPB, MaxDbpMbs]}
  82. avcdic = {'1' :['p',     64,    175,    396], '1b':['p',    128,    350,    396],
  83.           '11':['p',    192,    500,    900], '12':['p',    384,   1000,   2376],
  84.           '13':['p',    768,   2000,   2376], '2' :['p',   2000,   2000,   2376],
  85.           '21':['i',   4000,   4000,   4752], '22':['i',   4000,   4000,   8100],
  86.           '3' :['i',  10000,  10000,   8100], '31':['i',  14000,  14000,  18000],
  87.           '32':['i',  20000,  20000,  20480], '4' :['i',  20000,  25000,  32768],
  88.           '41':['i',  50000,  62500,  32768], '42':['p',  50000,  62500,  34816],
  89.           '5' :['p', 135000, 135000, 110400], '51':['p', 240000, 240000, 184320]}
  90. if len_opt > 1:
  91.     for i in range(len_opt):
  92.         try:
  93.             if options[i] == '-r' or options[i] == '--resolution':
  94.                 res    = options[i + 1].split('x')
  95.                 width  = int(res[0])
  96.                 height = int(res[1])
  97.             if options[i] == '-l' or options[i] == '--level':
  98.                 level = options[i + 1]
  99.             if options[i] == '-p' or options[i] == '--profile':
  100.                 prof = options[i + 1]
  101.             if options[i] == '-i' or options[i] == '--interlaced':
  102.                 mode = 'interlaced'
  103.             if options[i] == '-h' or options[i] == '--help':
  104.                 help = 1
  105.         except:
  106.             print "ERROR : invalid arguments\n"
  107.             help = 1
  108.         else:
  109.             pass
  110.     if help == 1:
  111.         usage()
  112.         sys.exit()
  113. else:
  114.     usage()
  115. profile = check_prof(prof, mode)
  116. lv_tmp  = check_level(level, mode, avcdic)
  117. mbs     = calc_mbs(width, height, mode)
  118. vbv     = calc_vbv(lv_tmp, profile, avcdic)
  119. maxref  = calc_maxref(lv_tmp, mbs, avcdic)
  120. print " resolution       : %i x %i" % (width, height)
  121. print " level            : %s" % level
  122. print " profile          : %s" % profile
  123. print " mode             : %s" % mode
  124. print " vbv-maxrate(vlc) : %i" % vbv[0]
  125. print " vbv-bufsize(vlc) : %i" % vbv[1]
  126. print " max ref number   : %i" % maxref


記不得是幾年前的東西了……

Follow me: @06_taro

MediaFire links to:
Taro's tools (avs plugins & other useful tools' builds)
Taro's x264 builds (Latest build: x264 core:129 r2245+704_tMod (&tMod+10bit/MixAQ/OreAQ), Win & MacOS, built on 10 Jan 2012, gcc: 4.7.2)

nmm牆內鏡像(部分工具)
级别: 新手上路
注册时间:
2011-11-17
在线时间:
7小时
发帖:
11
只看该作者 2楼 发表于: 2011-12-13
感谢楼上分享。分析了一下——
check_prof:判断是不是有效的档次。pr:档次;ip:隔行。
check_level:判断是不是有效的级别。lv:级别;ip:隔行;dic:数据字典。
calc_mbs:计算每帧宏块数。w:宽度;h:高度;ip:隔行。
calc_vbv:计算档次的码率。lv:级别;pr:档次;dic:数据字典。
calc_maxref:计算参考帧数。lv:级别;mbs:每帧宏块数;dic:数据字典。

优点:考虑了隔行、码率。
缺点:没有考虑帧率。

x264编码参数测试: 549335
快速回复

限150 字节
上一个 下一个