Skip to content

Commit

Permalink
v1.32
Browse files Browse the repository at this point in the history
* Removed the need for the binary mediainfo.exe (cli) - this has been replaced by an internal python module pymediainfo, it's a lot quicker/easier to use
* Removed lots of code that was related to mediainfocli
* Corrected part of the code to reset the config.ini file
* The "Start" button will no longer enable until you have selected a job (HDR or Dolby parser) or unless the program automatically does it for you
* Program now has the ability to detect if a file has BOTH Dolby Vision and HDR10+, in the event it detects both, the program will not automatically select which parser to use. You have to choose which you want and parse, if you want both, you will need to parse both separately and then feed both the json for hdr10+ and bin file for dolby vision to your encoder
* Added a new pop up message window when you hover your mouse over the Info label, this is for when the text inside is longer then you can see, you are able to hover the mouse over this and read all of it if you desire
* Added a new error window if the program was not able to automatically detect the HDR type, it tells you that it could not automatically detect, opens your web-browser to the github issue tracker where you can post a source sample and the error, in the event it actually was a programming error and not a user error
* Progress bars now rely on the new pymediainfo module, this is more simple/less code to use
*
  • Loading branch information
jessielw committed Dec 16, 2021
1 parent 3a169ac commit 2fc415b
Showing 1 changed file with 47 additions and 85 deletions.
132 changes: 47 additions & 85 deletions HDR-Multi-Tool-Gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import tkinter as tk
import pathlib, subprocess, shutil, threading, webbrowser
from TkinterDnD2 import *
from idlelib.tooltip import Hovertip
from pymediainfo import MediaInfo
from Packages.about import openaboutwindow
from configparser import ConfigParser

Expand All @@ -23,7 +25,7 @@ def root_exit_function(): # Asks if user wants to close main GUI + close all ta


root = TkinterDnD.Tk() # Main GUI with TkinterDnD function (for drag and drop)
root.title("HDR-Multi-Tool-Gui v1.3")
root.title("HDR-Multi-Tool-Gui v1.32")
root.iconphoto(True, PhotoImage(file="Runtime/Images/hdrgui.png"))
root.configure(background="#434547")
window_height = 400
Expand Down Expand Up @@ -60,11 +62,6 @@ def root_exit_function(): # Asks if user wants to close main GUI + close all ta
if not config.has_option('dolbyvision_tool_path', 'path'):
config.set('dolbyvision_tool_path', 'path', '')

if not config.has_section('mediainfocli_path'):
config.add_section('mediainfocli_path')
if not config.has_option('mediainfocli_path', 'path'):
config.set('mediainfocli_path', 'path', '')

if not config.has_section('debug_option'):
config.add_section('debug_option')
if not config.has_option('debug_option', 'option'):
Expand Down Expand Up @@ -154,22 +151,6 @@ def set_dolbyvision_tool_path():

options_menu.add_command(label='Set "dovi_tool.exe" path', command=set_dolbyvision_tool_path)


def set_mediainfocli_path():
global mediainfocli
path = filedialog.askopenfilename(title='Select Location to "MediaInfo.exe"', initialdir='/',
filetypes=[('MediaInfo', 'MediaInfo.exe')])
if path == '':
pass
elif path != '':
mediainfocli = '"' + str(pathlib.Path(path)) + '"'
config.set('mediainfocli_path', 'path', mediainfocli)
with open(config_file, 'w') as configfile:
config.write(configfile)


options_menu.add_command(label='Set "MediaInfo.exe" path', command=set_mediainfocli_path)

options_menu.add_separator()


Expand All @@ -179,7 +160,7 @@ def reset_config():
try:
config.set('ffmpeg_path', 'path', '')
config.set('hdr10plus_parser_path', 'path', '')
config.set('mediainfocli_path', 'path', '')
config.set('dolbyvision_tool_path', 'path', '')
with open(config_file, 'w') as configfile:
config.write(configfile)
messagebox.showinfo(title='Prompt', message='Please restart the program')
Expand All @@ -198,7 +179,6 @@ def reset_config():
# Bundled app path(s) -------------------------------------------------------------------------------------------------
ffmpeg = config['ffmpeg_path']['path']
hdr10plus_tool = config['hdr10plus_parser_path']['path']
mediainfocli = config['mediainfocli_path']['path']
dolbyvision_tool = config['dolbyvision_tool_path']['path']

if not pathlib.Path(ffmpeg.replace('"', '')).is_file(): # Checks config for bundled app paths path -------------------
Expand All @@ -211,12 +191,13 @@ def write_path_to_ffmpeg(): # Writes path to ffmpeg to the config.ini file
except (Exception,):
pass


if shutil.which('ffmpeg') is not None:
ffmpeg = '"' + str(pathlib.Path(shutil.which('ffmpeg'))).lower() + '"'
messagebox.showinfo(title='Prompt!', message='ffmpeg.exe found on system PATH, '
'automatically setting path to location.\n\n'
'Note: This can be changed in the config.ini file'
' or in the Options menu')
'automatically setting path to location.\n\n '
'Note: This can be changed in the config.ini file '
'or in the Options menu')
if pathlib.Path("Apps/ffmpeg/ffmpeg.exe").is_file():
rem_ffmpeg = messagebox.askyesno(title='Delete Included ffmpeg?',
message='Would you like to delete the included FFMPEG?')
Expand All @@ -232,23 +213,19 @@ def write_path_to_ffmpeg(): # Writes path to ffmpeg to the config.ini file
ffmpeg = str(pathlib.Path("Apps/ffmpeg/ffmpeg.exe"))
write_path_to_ffmpeg()
else:
error_prompt = messagebox.askyesno(title='Error!',
message='Cannot find ffmpeg, '
'please navigate to "ffmpeg.exe"')
error_prompt = messagebox.askyesno(title='Error!', message='Cannot find ffmpeg, '
'please navigate to "ffmpeg.exe"')
if not error_prompt:
messagebox.showerror(title='Error!',
message='Program requires ffmpeg.exe to work correctly')
messagebox.showerror(title='Error!', message='Program requires ffmpeg.exe to work correctly')
root.destroy()
if error_prompt:
set_ffmpeg_path()
if not pathlib.Path(ffmpeg).is_file():
messagebox.showerror(title='Error!',
message='Program requires ffmpeg.exe to work correctly')
messagebox.showerror(title='Error!', message='Program requires ffmpeg.exe to work correctly')
root.destroy()

# FFMPEG ------------------------------------------------------------------------------


if not pathlib.Path(hdr10plus_tool.replace('"', '')).is_file(): # Checks config for bundled app paths path
# HDR10plus_tool -----------------------------------------------------------------------
if pathlib.Path('Apps/HDR10PlusTool/hdr10plus_tool.exe').is_file():
Expand All @@ -267,26 +244,6 @@ def write_path_to_ffmpeg(): # Writes path to ffmpeg to the config.ini file
webbrowser.open('https://github.com/quietvoid/hdr10plus_tool/releases')
# hdr10plus_tool -------------------------------------------------------


if not pathlib.Path(mediainfocli.replace('"', '')).is_file(): # Checks config for bundled app paths path
# mediainfocli -------------------------------------------------------------
if pathlib.Path('Apps/MediaInfoCLI/MediaInfo.exe').is_file():
messagebox.showinfo(title='Info', message='Program will use the included '
'"MediaInfo.exe" located in the "Apps" folder')
mediainfocli = '"' + str(pathlib.Path('Apps/MediaInfoCLI/MediaInfo.exe')) + '"'
try:
config.set('mediainfocli_path', 'path', mediainfocli)
with open(config_file, 'w') as configfile:
config.write(configfile)
except (Exception,):
pass
elif not pathlib.Path('Apps/MediaInfoCLI/MediaInfo.exe').is_file():
messagebox.showerror(title='Error!', message='Please download mediainfo.exe and set path to '
'mediainfo.exe in the Options menu')
webbrowser.open('https://mediaarea.net/download/binary/mediainfo/21.09/MediaInfo_CLI_21.09_Windows_x64.zip')
# mediainfocli ----------------------------------------------------------


# dolbyvision_tool --------------------------------------------------------
if not pathlib.Path(dolbyvision_tool.replace('"', '')).is_file():
if pathlib.Path('Apps/dovi_tool/dovi_tool.exe').is_file():
Expand Down Expand Up @@ -363,6 +320,7 @@ def write_path_to_ffmpeg(): # Writes path to ffmpeg to the config.ini file
# HDR Parse Checkbutton -----------------------------------------------------------------------------------------------
def hdr10plus_parse():
dolbyvision_parse.set('off')
start_button.configure(state=NORMAL)


hdr_parse = StringVar()
Expand All @@ -379,6 +337,7 @@ def hdr10plus_parse():
# Dolby Vision Checkbutton --------------------------------------------------------------------------------------------
def dolby_parse():
hdr_parse.set('off')
start_button.configure(state=NORMAL)


dolbyvision_parse = StringVar()
Expand All @@ -389,7 +348,6 @@ def dolby_parse():
activeforeground="white", selectcolor="#434547", font=("Helvetica", 12))
dolbyvision_parse.set('off')


# -------------------------------------------------------------------------------------------- Dolby Vision Checkbutton

# Dolby Vision Crop Checkbutton ---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -434,32 +392,47 @@ def dobly_vision_mode_menu_hover_leave(e):

# Input Button Functions ----------------------------------------------------------------------------------------------
def check_for_hdr():
hdr_format_mediainfocli = '"' + mediainfocli + " " + '"--Inform=Video;%HDR_Format/String%"' \
+ " " + VideoInputQuoted + '"'
try:
mediainfo_duration = subprocess.Popen('cmd /c ' + hdr_format_mediainfocli,
creationflags=subprocess.CREATE_NO_WINDOW,
universal_newlines=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = mediainfo_duration.communicate()
if 'HDR10+' in stdout:
link_input_label.config(text=stdout.rstrip("\n"), anchor='center')
mediainfo_hdr_parse = MediaInfo.parse(VideoInputQuoted.replace('"', ''))
for track in mediainfo_hdr_parse.tracks:
if track.track_type == "Video":
hdr_format_string = ''.join(track.other_hdr_format)

if 'Dolby Vision' in hdr_format_string and 'HDR10+' in hdr_format_string: # Source is Dolby Vision and HDR10+
messagebox.showinfo(title='Information', message='Source file has both Dolby Vision and HDR10+\n\n'
'If you want to retain both HDR formats in your encode '
'you will need to parse HDR10+ AND Dolby Vision '
'separately to inject them into your encoder')
link_input_label.config(text=hdr_format_string.rstrip("\n"), anchor=W)
Hovertip(link_input_label, hdr_format_string.rstrip("\n"), hover_delay=600)
elif 'HDR10+' in hdr_format_string: # If source only has HDR10+
link_input_label.config(text=hdr_format_string.rstrip("\n"), anchor='center')
hdr_tool_tabs.select(hdr_frame)
hdr_parse.set('on')
dolbyvision_parse.set('off')
elif 'Dolby Vision' in stdout:
link_input_label.config(text=stdout.rstrip("\n"), anchor=W)
start_button.configure(state=NORMAL)
Hovertip(link_input_label, hdr_format_string.rstrip("\n"), hover_delay=600)
elif 'Dolby Vision' in hdr_format_string: # If source only has Dolby Vision
link_input_label.config(text=hdr_format_string.rstrip("\n"), anchor=W)
hdr_tool_tabs.select(dolby_frame)
hdr_parse.set('off')
dolbyvision_parse.set('on')
else:
start_button.configure(state=NORMAL)
Hovertip(link_input_label, hdr_format_string.rstrip("\n"), hover_delay=600)
else: # If source has no HDR
link_input_label.config(text='No Parsing Needed', anchor='center')
messagebox.showinfo(title="No Processing Needed", message="No need to parse anything other then an HDR10+"
"or Dolby Vision file.\n\n If you see this in "
"error please let me know on the github tracker "
"with a sample of the source file.")
Hovertip(link_input_label, 'No Parsing Needed', hover_delay=600)
except (Exception,):
pass
messagebox.showerror(title='Error', message='Could not automatically detect HDR type, please post on the '
'github tracker with a sample of the source file.\n\n'
'Program can still parse without automatic detection, just '
'select the proper HDR type from your file and start job.')
webbrowser.open('https://github.com/jlw4049/HDR-Multi-Tool-Gui/issues')


def input_button_commands():
global VideoInput, autosavefilename, autofilesave_dir_path, VideoInputQuoted, VideoOutput
Expand Down Expand Up @@ -490,7 +463,6 @@ def input_button_commands():
output_entry.insert(0, str(VideoOut))
output_entry.configure(state=DISABLED)
output_button.configure(state=NORMAL)
start_button.configure(state=NORMAL)
check_for_hdr()
else:
link_input_label.config(text='Please Open a Dolby Vision or HDR10+ compatible file', anchor='center')
Expand Down Expand Up @@ -538,7 +510,6 @@ def update_file_input(*args):
output_entry.insert(0, str(VideoOut))
output_entry.configure(state=DISABLED)
output_button.configure(state=NORMAL)
start_button.configure(state=NORMAL)
check_for_hdr()
else:
link_input_label.config(text='Please Open a Dolby Vision or HDR10+ compatible file', anchor='center')
Expand Down Expand Up @@ -571,20 +542,12 @@ def start_job():
VideoOutputQuoted = '"' + VideoOutput + '.bin"'

if shell_options.get() == "Default":
global total_duration
mediainfocli_cmd = '"' + mediainfocli + " " + '--Inform="General;%FileSize%"' \
+ " " + VideoInputQuoted + '"'

try:
mediainfo_duration = subprocess.Popen('cmd /c ' + mediainfocli_cmd,
creationflags=subprocess.CREATE_NO_WINDOW,
universal_newlines=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
stdout, stderr = mediainfo_duration.communicate()
math = int(stdout) / 1000
split = str(math)
total_duration = split.rsplit('.', 1)[0]
mediainfo_file_size = MediaInfo.parse(VideoInputQuoted.replace('"', ''))
for track in mediainfo_file_size.tracks:
if track.track_type == "General":
total_file_size = track.file_size
total_duration = str(int(total_file_size) / 1000).rsplit('.', 1)[0] # Compressed code for progress bars
except (Exception,):
pass

Expand Down Expand Up @@ -634,7 +597,6 @@ def close_window():
'-f hevc - -hide_banner -loglevel warning -stats|' \
+ dolbyvision_tool + ' ' + dobly_vision_mode_choices[dobly_vision_mode.get()] \
+ dolbyvision_crop.get() + ' extract-rpu - -o ' + str(VideoOutputQuoted) + '"'
print(finalcommand)
elif shell_options.get() == "Debug":
finalcommand = '"' + ffmpeg + ' -analyzeduration 100M -probesize 50M -i ' + VideoInputQuoted \
+ ' -map 0:v:0 -c:v:0 copy -vbsf hevc_mp4toannexb -f hevc - |' \
Expand Down

0 comments on commit 2fc415b

Please sign in to comment.