Last active
July 10, 2018 02:38
-
-
Save FrankWu100/9cf9a50c32853141b2583a8dce171da5 to your computer and use it in GitHub Desktop.
a simple python script to checkout RK Player support videos format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import os, sys | |
flag_debug = False | |
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 = '' | |
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:") | |
print (bcolors.WARNING + " sudo apt-get update") | |
print (" sudo apt-get install mediainfo" + bcolors.ENDC) | |
sys.exit() | |
# 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") | |
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" | |
# Start Check | |
support = False | |
# 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: | |
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: | |
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: | |
# 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 | |
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: | |
# Bit Rate 30Mbps | |
if v_BitRate <= 30*1024*1000: | |
support = True | |
else: | |
p_FormatSetting = bcolors.OKBLUE + p_FormatSetting + 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: | |
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 | |
# 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 | |
# 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 of Support" + bcolors.ENDC) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment