python.video_converter_v3/app/class_media_file.py

80 lines
No EOL
2.7 KiB
Python

import os
class Media:
_id_counter = 0
def __init__(self, path, streams_video, streams_audio, streams_subtitle, streams_format):
# misc
self.id = Media._id_counter
# source
self.source_file: str = path
self.source_file_name: str = os.path.basename(self.source_file)
self.source_size: int = 0
self.source_frames: int = 0
self.source_time: int = 0
# target
self.target_file: str = f"{path.rsplit(".", 1)[0]}.webm"
self.target_size: int = 0
# process
self.status = None
self.process_start: int = 0
self.process_end: int = 0
self.process_time: int = 0
self.process_size: int = 0
self.process_frames: int = 0
# statistic
self.stat_fps: list = [0, 0]
self.stat_bitrate: list = [0, 0]
self.stat_quantizer: list = [0, 0]
self.stat_speed: list = [0, 0]
# raw
self.streams_video = streams_video
self.streams_audio = streams_audio
self.streams_subtitle = streams_subtitle
self.streams_format = streams_format
# --------------------------------------------------------------------------------------------------------------
Media._id_counter += 1
def __str__(self):
def stream_output(stream_list):
count = 1
string = ""
for video_stream in stream_list:
string += f"{video_stream.get("codec_type").capitalize()} {count}" if video_stream.get(
"codec_type") else "Format"
for key, value in video_stream.items():
string += f" -- {key}: {value}"
string += "\n"
count += 1
return string
# Ausgabe
output_string = f"\n{self.source_file}\n"
output_string += "------------------------------------\n"
output_string += stream_output(self.streams_format)
output_string += "------------------------------------\n"
output_string += stream_output(self.streams_video)
output_string += "------------------------------------\n"
output_string += stream_output(self.streams_audio)
output_string += "------------------------------------\n"
output_string += stream_output(self.streams_subtitle)
output_string += "------------------------------------\n"
output_string += f"{self.target_file}\n"
output_string += "------------------------------------\n"
output_string += f"{self.id} -- {self.status}"
output_string += "\n************************************\n"
return output_string
@staticmethod
def to_dict():
return "Fertig mit der Welt"