FIX 修复视频剪裁

This commit is contained in:
15251370802 2025-03-05 15:43:01 +08:00
parent 810d903244
commit 32c1574d8e
2 changed files with 17 additions and 39 deletions

View File

@ -1,5 +1,4 @@
import glob
import json
import os
import shutil
import traceback
@ -7,29 +6,20 @@ import uuid
from datetime import datetime
import ffmpy
video_extensions = ['webm', 'mp4', 'mkv', 'gif', 'mov']
class VideoCut:
"""FFMPEG视频剪辑 -- !有卡顿问题 暂废弃"""
"""FFMPEG视频剪辑"""
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"config": ("STRING",),
"video_path": ("STRING",),
"mod": ("INT",),
"fps": ("FLOAT",),
"period_length": (
"INT",
{
"default": 10,
"min": 4,
"max": 100,
"step": 1,
"forceInput": True,
},
),
"video_path": ("STRING",{"placeholder": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
"start": ("STRING", {"default": "00:00:00"}),
"end": ("STRING", {"default": "00:00:10"}),
},
}
@ -42,16 +32,9 @@ class VideoCut:
CATEGORY = "不忘科技-自定义节点🚩"
def cut(self, config, video_path, mod, fps, period_length):
def cut(self, video_path, start, end):
# 原文件名
origin_fname = ".".join(video_path.split(os.sep)[-1].split(".")[:-1])
# 配置获取
mul = mod / fps
print("fps", fps)
config = json.loads(config)
if len(config.keys()) == 0:
return ("无法生成符合要求的片段",)
start, end = config["start"], config["end"]
# 新文件名 复制改名适配ffmpeg
uid = uuid.uuid1()
temp_fname = os.sep.join(
@ -70,7 +53,7 @@ class VideoCut:
[
*video_path.split(os.sep)[-1].split(".")[:-2],
video_path.split(os.sep)[-1].split(".")[-2]
+ "_output_%%03d_%s" % datetime.now().strftime("%Y%m%d_%H%M%S"),
+ "_output_%s" % datetime.now().strftime("%Y%m%d_%H%M%S"),
video_path.split(os.sep)[-1].split(".")[-1],
]
)
@ -83,23 +66,17 @@ class VideoCut:
)
# 调用ffmpeg
ff = ffmpy.FFmpeg(
inputs={video_path: ["-accurate_seek"]},
inputs={video_path: None},
outputs={
output: [
"-f",
"segment",
"-ss",
str(round(start * mul, 3)),
start,
"-to",
str(round(end * mul, 3)),
"-segment_times",
str(period_length),
"-c",
"copy",
"-map",
"0",
"-avoid_negative_ts",
"1",
end,
"-c:v",
"libx264",
"-c:a",
"copy"
]
},
)

View File

@ -5,4 +5,5 @@ Pillow
opencv-python
ultralytics
cos-python-sdk-v5
sqlalchemy
sqlalchemy
tencentcloud-sdk-python