diff --git a/app/main.py b/app/main.py index d568a50..d589304 100755 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,3 @@ -import asyncio import os.path import re import subprocess @@ -6,6 +5,7 @@ import json import logging import threading import time +import queue from datetime import date import uvicorn @@ -16,12 +16,13 @@ from fastapi.templating import Jinja2Templates from starlette.websockets import WebSocketState import app.video_class as vc -from app.ffmpeg_class import FfmpegCommands as fc -from app.config_class import Config as c +from app.ffmpeg_class import Ffmpeg as Fc +from app.config_class import Config as Cfg # Globale Variablen -config = c.Config() -ffmpeg: ffmpeg = fc.Ffmpeg(config) +config = Cfg().config + +ffmpeg = Fc(config) queue: queue = queue.Queue() semaphore = threading.Semaphore(config["convert"]["max_process"]) @@ -82,7 +83,7 @@ def get_video_information(media_path): return 0 def get_ffprobe(select, source_file): - command = ffmpeg.video_info() + command = ffmpeg.video_info(select, source_file) result = subprocess.run(command, stdout=subprocess.PIPE, text=True) json_data = json.loads(result.stdout) @@ -108,17 +109,13 @@ def video_convert(obj): semaphore.acquire() - result: str = None + result: str = "" obj.convert_start = time.time() - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - - command = ffmpeg.video_convert() + command = ffmpeg.video_convert(config, obj) logging.info(f"{command}") - loop.run_until_complete(queue.put(video_list())) - + # Prozess try: obj.process = subprocess.Popen( @@ -129,6 +126,7 @@ def video_convert(obj): active_process.add(obj) obj.finished = 3 + queue.put(video_list()) while obj.process.poll() is None: logging.info(f"{obj.file_name} ... Running") @@ -143,7 +141,7 @@ def video_convert(obj): logging.info(f"Process {result}({obj.process.returncode}): {obj.file_name}") - loop.run_until_complete(queue.put(obj.to_dict())) + queue.put(obj.to_dict()) active_process.discard(obj) active_tasks.discard(obj) @@ -164,7 +162,8 @@ def read_output(): while True: if not len(active_process): - time.sleep(5) + time.sleep(30) + queue.put(video_list()) continue for obj in list(active_process): @@ -210,7 +209,7 @@ async def websocket_v(websocket: WebSocket): if thread_output is None: # Startet den Thread zum Verarbeiten der Prozessausgaben - thread_output = threading.Thread(target=read_output, args=(queue,)) + thread_output = threading.Thread(target=read_output) thread_output.start() try: @@ -244,4 +243,4 @@ async def get_clients_count(): return {"active_clients": len(clients), "active_processes": len(active_process), "active_tasks": len(active_tasks)} if __name__ == "__main__": - uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=False) \ No newline at end of file + uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=False) \ No newline at end of file diff --git a/app/video_class.py b/app/video_class.py index a2aec00..a17fa92 100644 --- a/app/video_class.py +++ b/app/video_class.py @@ -134,8 +134,8 @@ class Video: self.fps = int(fps[0]) if fps else 0 # Quantizer - q = re.findall(r"q=\s*(\d+.\d+)", line_decoded) - self.q = int([0]) if q else 0 + q = re.findall(r"q=\s*(\d+).\d+", line_decoded) + self.q = int(q[0]) if q else 0 # File Size size = re.findall(r"size=\s*(\d+)", line_decoded) @@ -162,7 +162,7 @@ class Video: if len(hs_ms_s[0]) >= 3: if hs_ms_s[0][0].isdigit() and hs_ms_s[0][1].isdigit() and hs_ms_s[0][2].isdigit(): try: - return int(hs_ms_s[0][0]) * 60 + int(hs_ms_s[0][1]) * 60 + int(hs_ms_s[0][2]) + return int(hs_ms_s[0][0]) * 3600 + int(hs_ms_s[0][1]) * 60 + int(hs_ms_s[0][2]) except ValueError as e: logging.error(f"Wert: {time_str} Fehler: {e}") return 0