handler.py now fully operational with at least .mp4 videos, most likely also with other formats.

This commit is contained in:
janis
2022-09-04 21:53:00 +02:00
parent 229a4d6253
commit 2cded3acb3

View File

@@ -7,10 +7,12 @@
# #
########################################################### ###########################################################
import os import os
import sys import sys
import ffmpeg import ffmpeg
import configparser import configparser
import time
# Loading the config file to get user preferred temp path # Loading the config file to get user preferred temp path
config = configparser.ConfigParser() config = configparser.ConfigParser()
@@ -104,25 +106,55 @@ class Handler:
self.files = "" self.files = ""
self.filelist = os.listdir(self.tmppath) self.filelist = os.listdir(self.tmppath)
self.filelist.pop(0) self.filelist.pop(0)
self.filelist.reverse()
self.number = 0 self.number = 0
for self.file in self.filelist: for self.file in self.filelist:
self.number += 1 self.number += 1
if self.file == "": self.files += f"{self.tmppath}{self.file} {self.tmppath}upscaled/USImage{str(self.number).zfill(4)}.jpg "
pass
else:
self.files += f"{self.tmppath}{self.file} {self.tmppath}upscaled/USImage{self.number}.jpg "
self.maxlength = 32000 self.maxlength = 32000
self.pos = 1
# Refactoring of commands that are longer than 32K characters
if len(self.files) > self.maxlength: if len(self.files) > self.maxlength:
print("shrinking command length")
self.fileout = [] self.fileout = []
self.fileout.append(self.files[:self.maxlength])
self.filesopt = self.files[:self.maxlength] while self.files[self.maxlength - self.pos:self.maxlength - self.pos + 1] != " ":
self.pos += 1
self.file_processing = self.files[:self.maxlength - self.pos]
if self.file_processing[len(self.file_processing) - 13:len(self.file_processing) - 8] == "thumb":
self.pos += 5
else:
pass
while self.files[self.maxlength - self.pos:self.maxlength - self.pos + 1] != " ":
self.pos += 1
self.fileout.append(self.files[:self.maxlength - self.pos])
self.filesopt = self.files[self.maxlength - self.pos:]
self.posx = 0 self.posx = 0
self.posy = self.maxlength self.posy = self.maxlength
while len(self.filesopt) > self.maxlength:
self.posx += self.maxlength # Command refactoring for commands that are longer than 64K characters
self.posy += self.maxlength if len(self.filesopt) > self.maxlength:
self.fileout.append(self.files[self.posx:self.posy]) while len(self.filesopt) > self.maxlength:
self.posx += self.maxlength - self.pos
self.posy += self.maxlength - self.pos
self.pos = 1
while self.files[self.posy - self.pos:self.posy - self.pos + 1] != " ":
self.pos += 1
self.file_processing = self.files[self.posx:self.posy - self.pos]
if self.file_processing[len(self.file_processing) - 13:len(self.file_processing) - 8] == "thumb":
self.pos += 5
else:
pass
while self.files[self.posy - self.pos:self.posy - self.pos + 1] != " ":
self.pos += 1
self.file_processing = self.files[self.posx:self.posy - self.pos]
self.fileout.append(self.file_processing)
self.filesopt = self.files[self.posy - self.pos:]
self.fileout.append(self.filesopt)
else:
self.fileout.append(self.files[self.maxlength - self.pos:])
else: else:
self.fileout.append(self.files) self.fileout.append(self.files)
print("filepath assembled") print("filepath assembled")
@@ -133,7 +165,9 @@ class Handler:
pass pass
# Upscaling images # Upscaling images
for self.files_handle in self.fileout: print("\n\n\nUpscaling images... \n\n\n")
while self.fileout != []:
self.files_handle = self.fileout.pop(0)
if quality_mode == "default": if quality_mode == "default":
if self.os_type == "linux": if self.os_type == "linux":
self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.files_handle}" self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.files_handle}"
@@ -151,10 +185,15 @@ class Handler:
else: else:
print("OS CURRENTLY UNSUPPORTED!") print("OS CURRENTLY UNSUPPORTED!")
return False return False
print(self.command) print(self.command, "\n\n\nCOMMAND to EXECUTE\n\n\n")
os.system(self.command) os.system(self.command)
print("Finished upscaling this section.")
time.sleep(3)
# get Video's audio # get Video's audio
print("Retrieving Video's audio to append")
os.remove(f"{self.tmppath}audio.aac")
os.remove(f"{output_path}")
if self.os_type == "linux": if self.os_type == "linux":
self.command = f"ffmpeg -i {self.filepath} -vn -acodec copy {self.tmppath}audio.aac" self.command = f"ffmpeg -i {self.filepath} -vn -acodec copy {self.tmppath}audio.aac"
elif self.os_type == "win32": elif self.os_type == "win32":
@@ -162,3 +201,17 @@ class Handler:
else: else:
print("OS CURRENTLY UNSUPPORTED!") print("OS CURRENTLY UNSUPPORTED!")
return False return False
os.system(self.command)
# reassemble Video
print("Reassembling Video... with framerate @", self.framerate)
if self.os_type == "linux":
self.command = f"ffmpeg -framerate {self.framerate} -i {self.tmppath}upscaled/USImage%04d.jpg {output_path} -i {self.tmppath}audio.aac"
elif self.os_type == "win32":
self.command = f"{ffmpegpath} -framerate {self.framerate} -i {self.tmppath}upscaled/USImage%04d.jpg {output_path} -i {self.tmppath}audio.aac"
else:
print("OS CURRENTLY UNSUPPORTED!")
return False
os.system(self.command)
print("\n\n\n DONE \n\n\n\n")