ADD 增加ffmpeg转换fps日志输出

This commit is contained in:
kyj@bowong.ai 2025-04-24 14:42:02 +08:00
parent f20fa1e6fc
commit 7ba2931b0d
1 changed files with 24 additions and 5 deletions

View File

@ -1,6 +1,9 @@
import errno
import glob
import os
import shutil
import subprocess
import sys
import traceback
import uuid
from datetime import datetime
@ -8,6 +11,7 @@ from datetime import datetime
import ffmpy
import loguru
import torchvision.io
from ffmpy import FFExecutableNotFoundError, FFRuntimeError
video_extensions = ['webm', 'mp4', 'mkv', 'gif', 'mov']
@ -260,10 +264,10 @@ class VideoChangeFPS:
try:
if not (video_path.startswith("/") or video_path.startswith("output/") or video_path[1] == ":"):
video_path = "output/" + video_path
loguru.logger.info("Processing video: %s", video_path)
loguru.logger.info("Processing video: %s" % video_path)
output = ".".join([video_path.split(".")[-2]+"-%dfps" % fps,video_path.split(".")[-1]])
ff = ffmpy.FFmpeg(
inputs={video_path: None},
inputs={video_path: ["-loglevel", "info","-y"]},
outputs={
output: [
"-vf",
@ -274,12 +278,27 @@ class VideoChangeFPS:
"16",
"-preset",
"slow",
"-threads",
"12",
"-c:a",
"copy"
"copy",
]
})
print(ff.cmd)
ff.run()
try:
print(ff.cmd)
with open("user/ffmpeg.txt", "a") as log:
log.write("\n----"+f"{datetime.now()}----\n"+ff.cmd+"\n========\n")
process = subprocess.Popen(
ff.cmd, stdout=log, stderr=log
)
except OSError as e:
if e.errno == errno.ENOENT:
raise FFExecutableNotFoundError(f"Executable '{ff.executable}' not found")
else:
raise
o_stdout, o_stderr = process.communicate()
if process.returncode != 0:
raise FFRuntimeError(ff.cmd, process.returncode, o_stdout, o_stderr)
return (output,)
except:
traceback.print_exc()