Fehler beseitigt

This commit is contained in:
Eduard Wisch 2025-03-04 18:06:20 +01:00
parent e37ca3155c
commit 274c20449e
4 changed files with 38 additions and 22 deletions

15
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "app/main.py",
"console": "integratedTerminal"
}
]
}

View file

@ -1,8 +1,8 @@
class Ffmpeg:
def __init__(config):
def __init__(self, config):
self.config = config
def video_info():
def video_info(self, select, source_file):
command_info = [
"ffprobe", "-v",
"error",
@ -19,7 +19,7 @@ class Ffmpeg:
return command_info
def video_convert():
def video_convert(self, config, obj):
command_convert = [
"ffmpeg", "-y", "-i", obj.source_file,
"-map", "0:0",

View file

@ -6,6 +6,7 @@ import json
import logging
import threading
import time
import queue
from datetime import date
import uvicorn
@ -15,13 +16,15 @@ from fastapi.responses import HTMLResponse
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
import video_class as vc
from ffmpeg_class import Ffmpeg as fc
from config_class import Config as c
# Globale Variablen
config = c.Config()
ffmpeg: ffmpeg = fc.Ffmpeg(config)
cfg = c()
config = cfg.config
ffmpeg: ffmpeg = fc(config)
queue: queue = queue.Queue()
semaphore = threading.Semaphore(config["convert"]["max_process"])
@ -82,7 +85,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)
@ -111,14 +114,10 @@ def video_convert(obj):
result: str = None
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 +128,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 +143,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 +164,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 +211,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 +245,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)
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
# 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