Fehler beseitigt
This commit is contained in:
parent
e37ca3155c
commit
274c20449e
4 changed files with 38 additions and 22 deletions
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
class Ffmpeg:
|
class Ffmpeg:
|
||||||
def __init__(config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def video_info():
|
def video_info(self, select, source_file):
|
||||||
command_info = [
|
command_info = [
|
||||||
"ffprobe", "-v",
|
"ffprobe", "-v",
|
||||||
"error",
|
"error",
|
||||||
|
|
@ -19,7 +19,7 @@ class Ffmpeg:
|
||||||
|
|
||||||
return command_info
|
return command_info
|
||||||
|
|
||||||
def video_convert():
|
def video_convert(self, config, obj):
|
||||||
command_convert = [
|
command_convert = [
|
||||||
"ffmpeg", "-y", "-i", obj.source_file,
|
"ffmpeg", "-y", "-i", obj.source_file,
|
||||||
"-map", "0:0",
|
"-map", "0:0",
|
||||||
|
|
|
||||||
33
app/main.py
33
app/main.py
|
|
@ -6,6 +6,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
|
||||||
|
|
@ -15,13 +16,15 @@ from fastapi.responses import HTMLResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.websockets import WebSocketState
|
from starlette.websockets import WebSocketState
|
||||||
|
|
||||||
import app.video_class as vc
|
import video_class as vc
|
||||||
from app.ffmpeg_class import FfmpegCommands as fc
|
from ffmpeg_class import Ffmpeg as fc
|
||||||
from app.config_class import Config as c
|
from config_class import Config as c
|
||||||
|
|
||||||
# Globale Variablen
|
# Globale Variablen
|
||||||
config = c.Config()
|
cfg = c()
|
||||||
ffmpeg: ffmpeg = fc.Ffmpeg(config)
|
config = cfg.config
|
||||||
|
|
||||||
|
ffmpeg: 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 +85,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)
|
||||||
|
|
@ -111,14 +114,10 @@ def video_convert(obj):
|
||||||
result: str = None
|
result: str = None
|
||||||
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:
|
||||||
obj.process = subprocess.Popen(
|
obj.process = subprocess.Popen(
|
||||||
|
|
@ -129,6 +128,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 +143,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 +164,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 +211,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 +245,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)
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue