Skip to content

Instantly share code, notes, and snippets.

@FrankWu100
Last active July 10, 2018 02:38
Show Gist options
  • Save FrankWu100/9cf9a50c32853141b2583a8dce171da5 to your computer and use it in GitHub Desktop.
Save FrankWu100/9cf9a50c32853141b2583a8dce171da5 to your computer and use it in GitHub Desktop.

Revisions

  1. FrankWu100 revised this gist Jul 10, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion video_check.py
    Original file line number Diff line number Diff line change
    @@ -208,4 +208,4 @@ def format_check(result):
    if support:
    print (bcolors.OKGREEN + "Support" + bcolors.ENDC)
    else:
    print (bcolors.FAIL + "OUT support" + bcolors.ENDC)
    print (bcolors.FAIL + "Out of Support" + bcolors.ENDC)
  2. FrankWu100 revised this gist Jul 10, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion video_check.py
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ def disable(self):
    print (" sudo apt-get install mediainfo" + bcolors.ENDC)
    sys.exit()

    # creat rule file
    # create rule file
    rule_path = '.mediainfo_output_rule.dat'
    rule_f = open(rule_path, 'w+')
    rule_f.write("General;General: %FileName%.%FileExtension%|%OverallBitRate%|%OverallBitRate_Maximum%\\n\nVideo;Video: %Format%|%Width%|%Height%|%FrameRate%|%FrameRate_Original%|%BitRate%|%BitRate_Maximum%|%Format_Settings_CABAC%|%BitDepth%\n")
  3. FrankWu100 revised this gist Jul 10, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion video_check.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ def disable(self):
    self.FAIL = ''
    self.ENDC = ''

    if not os.popen("mediainfo"):
    if not os.popen("mediainfo").read():
    print (bcolors.FAIL + "ERROR: mediainfo: command not found" + bcolors.ENDC)
    print (" You need to install " + bcolors.HEADER + "MediaInfo" + bcolors.ENDC + " from apt-get first.")
    print (" Command:")
  4. FrankWu100 revised this gist Apr 3, 2017. No changes.
  5. FrankWu100 revised this gist Apr 3, 2017. No changes.
  6. FrankWu100 revised this gist Apr 2, 2017. 1 changed file with 3 additions and 11 deletions.
    14 changes: 3 additions & 11 deletions video_check.py
    Original file line number Diff line number Diff line change
    @@ -76,8 +76,9 @@ def format_check(result):
    p_BitRate = str(float(v_BitRate)/1000) + " Kbps"
    p_BitDepth = str(v_BitDepth) + " bit"

    support = False

    # Start Check
    support = False
    # H.264/AVC
    if v_Format == 'AVC':
    p_Format = "H.264/AVC"
    @@ -168,16 +169,7 @@ def format_check(result):
    else:
    p_Format = bcolors.FAIL + v_Format + bcolors.ENDC

    # class bcolors:
    # HEADER = '\033[95m'
    # OKBLUE = '\033[94m'
    # OKGREEN = '\033[92m'
    # WARNING = '\033[93m'
    # FAIL = '\033[91m'
    # ENDC = '\033[0m'
    #
    # Print Format

    # Print Format
    print ("---- Format ----")
    if v_Format == 'AVC':
    print ("Format : " + p_Format)
  7. FrankWu100 revised this gist Apr 2, 2017. 1 changed file with 21 additions and 6 deletions.
    27 changes: 21 additions & 6 deletions video_check.py
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@

    import os, sys

    flag_debug = True
    flag_debug = False

    class bcolors:
    HEADER = '\033[95m'
    @@ -89,10 +89,16 @@ def format_check(result):
    if v_BitRate <= 60*1024*1000:
    support = True
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    if p_Resolution != "1920x1080":
    p_Resolution = p_Resolution + bcolors.OKBLUE + " (1920x1080)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 60 Mbps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    if p_Resolution != "1920x1080":
    p_Resolution = p_Resolution + bcolors.OKBLUE + " (1920x1080)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_FrameRate = bcolors.FAIL + p_FrameRate + bcolors.OKBLUE + " (Max: 60 fps)" + bcolors.ENDC
    # 4K
    elif v_Height <= 4096 and v_Width <= 2304:
    @@ -105,7 +111,10 @@ def format_check(result):
    support = True
    else:
    p_FormatSetting = bcolors.OKBLUE + p_FormatSetting + bcolors.ENDC
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    if p_Resolution != "4096x2304":
    p_Resolution = p_Resolution + bcolors.OKBLUE + " (4096x2304)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 60 Mbps)" + bcolors.ENDC
    # CAVLC
    else:
    @@ -114,10 +123,16 @@ def format_check(result):
    support = True
    else:
    p_FormatSetting = bcolors.OKBLUE + p_FormatSetting + bcolors.ENDC
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    if p_Resolution != "4096x2304":
    p_Resolution = p_Resolution + bcolors.OKBLUE + " (4096x2304)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 30 Mbps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    if p_Resolution != "4096x2304":
    p_Resolution = p_Resolution + bcolors.OKBLUE + " (4096x2304)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_FrameRate = bcolors.FAIL + p_FrameRate + bcolors.OKBLUE + " (Max: 25 fps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.FAIL + p_Resolution + bcolors.OKBLUE + " (Max: 4096x2304)" + bcolors.ENDC
  8. FrankWu100 revised this gist Apr 2, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion video_check.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ def disable(self):
    self.FAIL = ''
    self.ENDC = ''

    if os.popen("mediainfo"):
    if not os.popen("mediainfo"):
    print (bcolors.FAIL + "ERROR: mediainfo: command not found" + bcolors.ENDC)
    print (" You need to install " + bcolors.HEADER + "MediaInfo" + bcolors.ENDC + " from apt-get first.")
    print (" Command:")
  9. FrankWu100 revised this gist Apr 2, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions video_check.py
    Original file line number Diff line number Diff line change
    @@ -21,8 +21,7 @@ def disable(self):
    self.FAIL = ''
    self.ENDC = ''

    result = os.popen("mediainfo").read().strip()
    if result == "-bash: mediainfo: command not found":
    if os.popen("mediainfo"):
    print (bcolors.FAIL + "ERROR: mediainfo: command not found" + bcolors.ENDC)
    print (" You need to install " + bcolors.HEADER + "MediaInfo" + bcolors.ENDC + " from apt-get first.")
    print (" Command:")
  10. FrankWu100 created this gist Apr 2, 2017.
    205 changes: 205 additions & 0 deletions video_check.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,205 @@
    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    import os, sys

    flag_debug = True

    class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

    def disable(self):
    self.HEADER = ''
    self.OKBLUE = ''
    self.OKGREEN = ''
    self.WARNING = ''
    self.FAIL = ''
    self.ENDC = ''

    result = os.popen("mediainfo").read().strip()
    if result == "-bash: mediainfo: command not found":
    print (bcolors.FAIL + "ERROR: mediainfo: command not found" + bcolors.ENDC)
    print (" You need to install " + bcolors.HEADER + "MediaInfo" + bcolors.ENDC + " from apt-get first.")
    print (" Command:")
    print (bcolors.WARNING + " sudo apt-get update")
    print (" sudo apt-get install mediainfo" + bcolors.ENDC)
    sys.exit()

    # creat rule file
    rule_path = '.mediainfo_output_rule.dat'
    rule_f = open(rule_path, 'w+')
    rule_f.write("General;General: %FileName%.%FileExtension%|%OverallBitRate%|%OverallBitRate_Maximum%\\n\nVideo;Video: %Format%|%Width%|%Height%|%FrameRate%|%FrameRate_Original%|%BitRate%|%BitRate_Maximum%|%Format_Settings_CABAC%|%BitDepth%\n")
    rule_f.close()

    def format_check(result):
    # get info
    result = result.split('\n')
    result_General = result[0].split("General: ")[1].split('|')
    result_Video = result[1].split("Video: ")[1].split('|')

    v_Format = result_Video[0]
    v_Height = int(result_Video[1])
    v_Width = int(result_Video[2])
    v_FrameRate = result_Video[3]
    if not v_FrameRate:
    v_FrameRate = result_Video[4]
    if v_FrameRate:
    v_FrameRate = float(v_FrameRate)
    v_BitRate = result_Video[6]
    if not v_BitRate:
    v_BitRate = result_Video[5]
    if not v_BitRate:
    v_BitRate = result_General[2]
    if not v_BitRate:
    v_BitRate = result_General[1]
    if v_BitRate:
    v_BitRate = int(v_BitRate)
    v_CABAC = result_Video[7]
    if v_CABAC == "Yes":
    v_CABAC = True
    else:
    v_CABAC = False
    v_BitDepth = int(result_Video[8])

    p_Format = ""
    p_FormatSetting = "CABAC" if v_CABAC else "CAVLC"
    p_Resolution = str(v_Height) + "x" + str(v_Width)
    p_FrameRate = str(v_FrameRate) + " fps"
    p_BitRate= ""
    if v_BitRate/1024/1000 >= 10:
    p_BitRate = str(float(v_BitRate/1024)/1000) + " Mbps"
    else:
    p_BitRate = str(float(v_BitRate)/1000) + " Kbps"
    p_BitDepth = str(v_BitDepth) + " bit"

    support = False
    # Start Check
    # H.264/AVC
    if v_Format == 'AVC':
    p_Format = "H.264/AVC"
    # 1080P
    if v_Height <= 1920 and v_Width <= 1080:
    # 60FPS
    if v_FrameRate <= 60:
    # Bit Rate 60Mbps
    if v_BitRate <= 60*1024*1000:
    support = True
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 60 Mbps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_FrameRate = bcolors.FAIL + p_FrameRate + bcolors.OKBLUE + " (Max: 60 fps)" + bcolors.ENDC
    # 4K
    elif v_Height <= 4096 and v_Width <= 2304:
    # 25FPS
    if v_FrameRate <= 25:
    # CABAC
    if v_CABAC:
    # Bit Rate 60Mbps
    if v_BitRate <= 60*1024*1000:
    support = True
    else:
    p_FormatSetting = bcolors.OKBLUE + p_FormatSetting + bcolors.ENDC
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 60 Mbps)" + bcolors.ENDC
    # CAVLC
    else:
    # Bit Rate 30Mbps
    if v_BitRate <= 30*1024*1000:
    support = True
    else:
    p_FormatSetting = bcolors.OKBLUE + p_FormatSetting + bcolors.ENDC
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 30 Mbps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.OKBLUE + p_Resolution + bcolors.ENDC
    p_FrameRate = bcolors.FAIL + p_FrameRate + bcolors.OKBLUE + " (Max: 25 fps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.FAIL + p_Resolution + bcolors.OKBLUE + " (Max: 4096x2304)" + bcolors.ENDC
    # H.265/HEVC
    elif v_Format == 'HEVC':
    p_Format = "H.265/HEVC"
    # 4K
    if v_Height <= 4096 and v_Width <= 2304:
    # 60FPS
    if v_FrameRate <= 60:
    # 8Bit Depth
    if v_BitDepth == 8:
    # Bit Rate 80Mbps
    if v_BitRate <= 80*1024*1000:
    support = True
    else:
    p_BitDepth = bcolors.OKBLUE + p_BitDepth + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 80 Mbps)" + bcolors.ENDC
    # 10Bit Depth
    elif v_BitDepth == 10:
    # Bit Rate 50Mbps
    if v_BitRate <= 50*1024*1000:
    support = True
    else:
    p_BitDepth = bcolors.OKBLUE + p_BitDepth + bcolors.ENDC
    p_BitRate = bcolors.FAIL + p_BitRate + bcolors.OKBLUE + " (Max: 50 Mbps)" + bcolors.ENDC
    else:
    p_BitDepth = bcolors.FAIL + p_BitDepth + bcolors.OKBLUE + " (Max: 10 bit)" + bcolors.ENDC
    else:
    p_FrameRate = bcolors.FAIL + p_FrameRate + bcolors.OKBLUE + " (Max: 60 fps)" + bcolors.ENDC
    else:
    p_Resolution = bcolors.FAIL + p_Resolution + bcolors.OKBLUE + " (Max: 4096x2304)" + bcolors.ENDC
    else:
    p_Format = bcolors.FAIL + v_Format + bcolors.ENDC

    # class bcolors:
    # HEADER = '\033[95m'
    # OKBLUE = '\033[94m'
    # OKGREEN = '\033[92m'
    # WARNING = '\033[93m'
    # FAIL = '\033[91m'
    # ENDC = '\033[0m'
    #
    # Print Format

    print ("---- Format ----")
    if v_Format == 'AVC':
    print ("Format : " + p_Format)
    print ("Format Setting : " + ("CABAC" if v_CABAC else "CAVLC"))
    print ("Resolution : " + p_Resolution)
    print ("Frame Rate : " + p_FrameRate)
    print ("Bit Rate : " + p_BitRate)
    elif v_Format == 'HEVC':
    print ("Format : " + p_Format)
    print ("Resolution : " + p_Resolution)
    print ("Frame Rate : " + p_FrameRate)
    print ("Bit Rate : " + p_BitRate)
    print ("Bit Depth : " + p_BitDepth)
    else:
    print ("Format : " + v_Format)

    return support

    # start
    if len(sys.argv) < 2:
    print ("Usage: \"python " + __file__ + " FileName\"")
    sys.exit()
    file_path = os.path.realpath(sys.argv[1])

    result = os.popen("mediainfo --Output=file://" + rule_path + " \"" + file_path + "\"").read().strip()

    if flag_debug:
    print (file_path)
    print ("--------")
    print (result)
    print ("--------")

    support = format_check(result)

    print ("---- Result ----")
    if support:
    print (bcolors.OKGREEN + "Support" + bcolors.ENDC)
    else:
    print (bcolors.FAIL + "OUT support" + bcolors.ENDC)