Updated handler.py to be more stable and have more functions. Still cannot upscale videos!

This commit is contained in:
janis
2022-09-04 18:29:29 +02:00
parent 9ac016188d
commit 836c5de20c

View File

@@ -84,38 +84,81 @@ class Handler:
self.framerate = round(float(self.frames) / float(self.duration), 1)
# Splitting video into frames
print(self.filepath)
try:
os.mkdir(self.tmppath)
except FileExistsError:
pass
if self.os_type == "linux":
print("linux")
self.command = f"ffmpeg -i {str(self.filepath)} thumb%04d.jpg -hide_banner"
self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}thumb%04d.jpg -hide_banner"
elif self.os_type == "win32":
self.command = f"{ffmpegpath} -i {str(self.filepath)} thumb%04d.jpg -hide_banner"
self.command = f"{ffmpegpath} -i {str(self.filepath)} {self.tmppath}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}"
# Locate Images and assemble FSR-Command
self.files = ""
self.filelist = os.listdir(self.tmppath)
self.number = 0
for self.file in self.filelist:
self.number += 1
if self.file == "":
pass
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
self.files += f"{self.tmppath}{self.file} {self.tmppath}upscaled/USImage{self.number}.jpg"
self.maxlength = 32000
print(self.files)
if len(self.files) > self.maxlength:
self.fileout = []
self.fileout.append(self.files[:self.maxlength])
self.filesopt = self.files[:self.maxlength]
self.posx = 0
self.posy = self.maxlength
while len(self.filesopt) > self.maxlength:
self.posx += self.maxlength
self.posy += self.maxlength
self.fileout.append(self.files[self.posx:self.posy])
else:
self.fileout.append(self.files)
print("filepath assembled")
try:
os.mkdir(f"{self.tmppath}upscaled/")
except FileExistsError:
pass
# Upscaling images
for self.files_handle in self.fileout:
if quality_mode == "default":
if self.os_type == "linux":
self.command = f"wine {fsrpath} -Scale {quality_setting} {self.files} {output_path}"
self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.files_handle}"
elif self.os_type == "win32":
self.command = f" {fsrpath} -Scale {quality_setting} {self.files} {output_path}"
self.command = f"{fsrpath} -QualityMode {quality_setting} {self.files_handle}"
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_handle} {self.tmppath}"
elif self.os_type == "win32":
self.command = f"{fsrpath} -Scale {quality_setting} {self.files_handle} {self.tmppath}"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
print(self.command)
os.system(self.command)
os.system(self.command)
# get Video's audio
if self.os_type == "linux":
self.command = f"ffmpeg -i {self.filepath} -vn -acodec copy {self.tmppath}audio.aac"
elif self.os_type == "win32":
self.command = f"{ffmpegpath} -i {self.filepath} -vn -acodec copy {self.tmppath}audio.aac"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False