Initial development. Not yet ready to use!

This commit is contained in:
janis
2022-09-04 17:54:26 +02:00
parent cfc3a0f361
commit 9ac016188d
12 changed files with 283 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

8
.idea/FSRImageVideoUpscalerFrontend.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FSRImageVideoUpscalerFrontend.iml" filepath="$PROJECT_DIR$/.idea/FSRImageVideoUpscalerFrontend.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

121
bin/handler.py Normal file
View File

@@ -0,0 +1,121 @@
###########################################################
#
# Handler for FSRImageVideoUpscalerFrontend
#
# This code is licensed under the GPL V3 License!
# Developed 2022 by Janis Hutz
#
###########################################################
import os
import sys
import ffmpeg
import configparser
# Loading the config file to get user preferred temp path
config = configparser.ConfigParser()
config.read('../config/settings.ini')
class Handler:
def __init__(self):
self.os_type = sys.platform
self.command = ""
self.tmppath = ""
self.videometa = {}
def handler(self, fsrpath, filepath, quality_mode, quality_setting, output_path, ffmpegpath):
# Function to be called when using this class as this function automatically determines if file is video or image
if self.os_type == "linux":
self.tmppath = "/tmp/fsru/" # config["PathSettings"]["tmpPathLinux"]
elif self.os_type == "win32":
self.tmppath = config["PathSettings"]["tmpPathWindows"]
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
# checking for spaces in filepath (for use with terminal commands)
self.filepath = ""
for self.letter in filepath:
if self.letter == " ":
self.filepath += "\ "
else:
self.filepath += self.letter
# Determining filetype
if str(filepath)[len(filepath) - 4:] == ".mp4" or str(filepath)[len(filepath) - 4:] == ".mkv":
print("upscaling video")
self.video_scaling(ffmpegpath, fsrpath, filepath, quality_mode, quality_setting, output_path)
elif str(filepath)[len(filepath) - 4:] == ".JPG" or str(filepath)[len(filepath) - 4:] == ".png" or str(filepath)[len(filepath) - 4:] == ".jpg":
print("upscaling image")
self.photo_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path)
else:
print("not supported")
def photo_scaling(self, fsrpath, filepath, quality_mode, quality_setting, output_path):
# DO NOT CALL THIS! Use Handler().handler() instead!
if quality_mode == "default":
if self.os_type == "linux":
self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.filepath} {output_path}"
elif self.os_type == "win32":
self.command = f"{fsrpath} -QualityMode {quality_setting} {self.filepath} {output_path}"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
os.system(self.command)
print("photo upscaled")
else:
if self.os_type == "linux":
self.command = f"wine {fsrpath} -Scale {quality_setting} {self.filepath} {output_path}"
elif self.os_type == "win32":
self.command = f"{fsrpath} -Scale {quality_setting} {self.filepath} {output_path}"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
os.system(self.command)
print("photo upscaled")
def video_scaling(self, ffmpegpath, fsrpath, filepath, quality_mode, quality_setting, output_path):
# DO NOT CALL THIS! Use Handler().handler() instead!
self.videometa = ffmpeg.probe(str(filepath))["streams"].pop(0)
# Retrieving Video metadata
self.duration = self.videometa.get("duration")
self.frames = self.videometa.get("nb_frames")
self.framerate = round(float(self.frames) / float(self.duration), 1)
# Splitting video into frames
print(self.filepath)
if self.os_type == "linux":
print("linux")
self.command = f"ffmpeg -i {str(self.filepath)} thumb%04d.jpg -hide_banner"
elif self.os_type == "win32":
self.command = f"{ffmpegpath} -i {str(self.filepath)} thumb%04d.jpg -hide_banner"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
os.system(self.command)
print("video split")
self.files = self.tmppath
self.filelist = os.listdir(self.tmppath)
for self.file in self.filelist:
self.files += f"{self.tmppath}{self.file}"
if quality_mode == "default":
if self.os_type == "linux":
self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.files} {output_path}"
elif self.os_type == "win32":
self.command = f" {fsrpath} -QualityMode {quality_setting} {self.files} {output_path}"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
else:
if quality_mode == "default":
if self.os_type == "linux":
self.command = f"wine {fsrpath} -Scale {quality_setting} {self.files} {output_path}"
elif self.os_type == "win32":
self.command = f" {fsrpath} -Scale {quality_setting} {self.files} {output_path}"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
os.system(self.command)

BIN
bin/lib/FidelityFX_CLI.exe Normal file

Binary file not shown.

7
config/settings.ini Normal file
View File

@@ -0,0 +1,7 @@
[PathSettings]
defaultOutputPath = $HOME/FSRImageVideoUpscaler/
tmpPathLinux = /tmp/
tmpPathWindows = %TEMP%
[DevSettings]
loggerReqLevel = DEBUG

17
dev/get_metadata.py Normal file
View File

@@ -0,0 +1,17 @@
import ffmpeg
class MetaDataParser:
def __init__(self):
pass
def get_metadata(self, filepath):
return ffmpeg.probe(str(filepath))["streams"]
videometa = MetaDataParser().get_metadata("/mnt/storage/SORTED/Videos/OBS_Rec/Behalten/2019-12-19 18-21-36.mp4").pop(0)
duration = videometa.get("duration")
frames = videometa.get("nb_frames")
framerate = float(frames) / float(duration)
print(framerate)
print(videometa)

4
dev/test.py Normal file
View File

@@ -0,0 +1,4 @@
import os
test = f"ffmpeg"
os.system(test)

99
fsrimagevideoupscaler.py Normal file
View File

@@ -0,0 +1,99 @@
###########################################################
#
# FSRImageVideoUpscalerFrontend written in GTK+
#
# This code is licensed under the GPL V3 License!
# Developed 2022 by Janis Hutz
#
###########################################################
import gi
import bin.handler
import multiprocessing
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
handler = bin.handler.Handler()
class HomeWindow(Gtk.Window):
def __init__(self):
super().__init__(title="Test")
self.filechooserdialog = Gtk.FileChooserDialog(title="Choose input file", action=Gtk.FileChooserAction.OPEN)
self.filechooserdialog_save = Gtk.FileChooserDialog(title="Choose output file", action=Gtk.FileChooserAction.SAVE)
# Spawn box
self.box = Gtk.Box(spacing=6)
self.add(self.box)
# Create filechooser button
self.filechoosebutton = Gtk.Button(label="Choose Input File")
self.filechoosebutton.connect("clicked", self.filechooser_clicked)
self.box.pack_start(self.filechoosebutton, True, True, 10)
# Create output filechooser button
self.opfchooserbutton = Gtk.Button(label="Choose Output File")
self.opfchooserbutton.connect("clicked", self.opfilechooser_clicked)
self.box.pack_start(self.opfchooserbutton, True, True, 10)
# Create start button
self.start_button = Gtk.Button(label="Start upscaling")
self.start_button.connect("clicked", self.start_clicked)
self.box.pack_start(self.start_button, True, True, 10)
def filechooser_clicked(self, widget):
self.filechooserdialog = Gtk.FileChooserDialog(title="Choose input file", action=Gtk.FileChooserAction.OPEN)
self.filechooserdialog.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN,
Gtk.ResponseType.OK,
)
self.response = self.filechooserdialog.run()
if self.response == Gtk.ResponseType.OK:
print("ok, selected file:", self.filechooserdialog.get_filename())
elif self.response == Gtk.ResponseType.CANCEL:
print("cancel")
self.filechooserdialog.destroy()
def opfilechooser_clicked(self, widget):
self.filechooserdialog_save = Gtk.FileChooserDialog(title="Choose output file", action=Gtk.FileChooserAction.SAVE)
Gtk.FileChooser.set_do_overwrite_confirmation(self.filechooserdialog_save, True)
Gtk.FileChooser.set_filename(self.filechooserdialog_save, "Test")
self.filechooserdialog_save.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE,
Gtk.ResponseType.OK,
)
self.response = self.filechooserdialog_save.run()
if self.response == Gtk.ResponseType.OK:
print("ok, selected file:", self.filechooserdialog_save.get_filename())
elif self.response == Gtk.ResponseType.CANCEL:
print("cancel")
self.filechooserdialog_save.destroy()
def start_clicked(self, widget):
print(str(Gtk.FileChooser.get_filename(self.filechooserdialog)))
if str(Gtk.FileChooser.get_filename(self.filechooserdialog)) != "" and str(Gtk.FileChooser.get_filename(self.filechooserdialog_save)) != "":
self.scaler = multiprocessing.Process(name="scaler",
target=handler.handler,
args=("./bin/lib/FidelityFX_CLI.exe",
"/mnt/storage/SORTED/Videos/OBS_Rec/Behalten/2019-12-19 18-21-36.mp4",
"default",
"Quality",
"./test.mp4",
"./bin/lib/ffmpeg.exe")
)
self.scaler.start()
else:
print("no file specified")
win = HomeWindow()
win.set_default_size(800, 600)
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()