37 lines
1.1 KiB
Python
37 lines
1.1 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())
|
|
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()
|