Merge remote-tracking branch 'origin/main'

# Conflicts:
#	app/ffmpeg_class.py
This commit is contained in:
Eduard Wisch 2025-03-05 20:48:04 +01:00
commit 8901279432
2 changed files with 19 additions and 20 deletions

View file

@ -1,4 +1,3 @@
import asyncio
import os.path import os.path
import re import re
import subprocess import subprocess
@ -6,6 +5,7 @@ import json
import logging import logging
import threading import threading
import time import time
import queue
from datetime import date from datetime import date
import uvicorn import uvicorn
@ -16,12 +16,13 @@ from fastapi.templating import Jinja2Templates
from starlette.websockets import WebSocketState from starlette.websockets import WebSocketState
import app.video_class as vc import app.video_class as vc
from app.ffmpeg_class import FfmpegCommands as fc from app.ffmpeg_class import Ffmpeg as Fc
from app.config_class import Config as c from app.config_class import Config as Cfg
# Globale Variablen # Globale Variablen
config = c.Config() config = Cfg().config
ffmpeg: ffmpeg = fc.Ffmpeg(config)
ffmpeg = Fc(config)
queue: queue = queue.Queue() queue: queue = queue.Queue()
semaphore = threading.Semaphore(config["convert"]["max_process"]) semaphore = threading.Semaphore(config["convert"]["max_process"])
@ -82,7 +83,7 @@ def get_video_information(media_path):
return 0 return 0
def get_ffprobe(select, source_file): 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) result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
json_data = json.loads(result.stdout) json_data = json.loads(result.stdout)
@ -108,16 +109,12 @@ def video_convert(obj):
semaphore.acquire() semaphore.acquire()
result: str = None result: str = ""
obj.convert_start = time.time() obj.convert_start = time.time()
loop = asyncio.new_event_loop() command = ffmpeg.video_convert(config, obj)
asyncio.set_event_loop(loop)
command = ffmpeg.video_convert()
logging.info(f"{command}") logging.info(f"{command}")
loop.run_until_complete(queue.put(video_list()))
# Prozess # Prozess
try: try:
@ -129,6 +126,7 @@ def video_convert(obj):
active_process.add(obj) active_process.add(obj)
obj.finished = 3 obj.finished = 3
queue.put(video_list())
while obj.process.poll() is None: while obj.process.poll() is None:
logging.info(f"{obj.file_name} ... Running") 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}") 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_process.discard(obj)
active_tasks.discard(obj) active_tasks.discard(obj)
@ -164,7 +162,8 @@ def read_output():
while True: while True:
if not len(active_process): if not len(active_process):
time.sleep(5) time.sleep(30)
queue.put(video_list())
continue continue
for obj in list(active_process): for obj in list(active_process):
@ -210,7 +209,7 @@ async def websocket_v(websocket: WebSocket):
if thread_output is None: if thread_output is None:
# Startet den Thread zum Verarbeiten der Prozessausgaben # 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() thread_output.start()
try: 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)} return {"active_clients": len(clients), "active_processes": len(active_process), "active_tasks": len(active_tasks)}
if __name__ == "__main__": if __name__ == "__main__":
uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=False) uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=False)

View file

@ -134,8 +134,8 @@ class Video:
self.fps = int(fps[0]) if fps else 0 self.fps = int(fps[0]) if fps else 0
# Quantizer # Quantizer
q = re.findall(r"q=\s*(\d+.\d+)", line_decoded) q = re.findall(r"q=\s*(\d+).\d+", line_decoded)
self.q = int([0]) if q else 0 self.q = int(q[0]) if q else 0
# File Size # File Size
size = re.findall(r"size=\s*(\d+)", line_decoded) size = re.findall(r"size=\s*(\d+)", line_decoded)
@ -162,7 +162,7 @@ class Video:
if len(hs_ms_s[0]) >= 3: 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(): if hs_ms_s[0][0].isdigit() and hs_ms_s[0][1].isdigit() and hs_ms_s[0][2].isdigit():
try: 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: except ValueError as e:
logging.error(f"Wert: {time_str} Fehler: {e}") logging.error(f"Wert: {time_str} Fehler: {e}")
return 0 return 0