2024-12-24 14:59:52 +08:00

40 lines
1.2 KiB
Python

import os
from datetime import datetime
from typing import Optional, IO
from entity.ffmpeg import FfmpegTask
def start_render(ffmpeg_task: FfmpegTask):
print(ffmpeg_task)
print(ffmpeg_task.get_ffmpeg_args())
if not ffmpeg_task.need_run():
ffmpeg_task.set_output_file(ffmpeg_task.input_file[0])
return True
code = os.system("ffmpeg.exe "+" ".join(ffmpeg_task.get_ffmpeg_args()))
return code == 0
def handle_ffmpeg_output(stdout: Optional[IO[bytes]]) -> str:
out_time = "0:0:0.0"
if stdout is None:
print("[!]STDOUT is null")
return out_time
speed = "0"
while True:
line = stdout.readline()
if line == b"":
break
if line.strip() == b"progress=end":
# 处理完毕
break
if line.startswith(b"out_time="):
out_time = line.replace(b"out_time=", b"").decode().strip()
if line.startswith(b"speed="):
speed = line.replace(b"speed=", b"").decode().strip()
print("[ ]Speed:", out_time, "@", speed)
return out_time
def duration_str_to_float(duration_str: str) -> float:
_duration = datetime.strptime(duration_str, "%H:%M:%S.%f") - datetime(1900, 1, 1)
return _duration.total_seconds()