python.fast-api-converter/app/video_class.py
2025-02-17 13:23:40 +01:00

53 lines
1.4 KiB
Python

import os
class Video:
def __init__(self, path):
self.id = id(self)
self.source_file = path
self.output_file = f"{path.rsplit(".", 1)[0]}.webm"
self.frame = None
self.fps = None
self.q = None
self.size = None
self.time = 0
self.bitrate = None
self.speed = None
self.finished = 0
self.progress = None
self.duration = 1
self.loading = 0
self.error = []
def to_dict(self):
self.calc_loading()
return {
"source": os.path.basename(self.source_file),
"target": os.path.basename(self.output_file),
"path": os.path.dirname(self.source_file),
"id": self.id,
"frame": self.frame,
"fps": self.fps,
"q": self.q,
"size": self.size,
"time": self.time,
"bitrate": self.bitrate,
"speed": self.speed,
"finished": self.finished,
"duration": self.duration,
"loading": self.loading
}
@staticmethod
def time_in_sec(time):
if time != 0:
h_m_s = str(time).split(":")
time_in_s = int(h_m_s[0]) * 3600 + int(h_m_s[1]) * 60 + int(h_m_s[2])
else:
time_in_s = 0
return time_in_s
def calc_loading(self):
self.loading = round(self.time / float(self.duration) * 100, None)