FIX 修复视频剪裁
This commit is contained in:
parent
810d903244
commit
32c1574d8e
|
|
@ -1,5 +1,4 @@
|
||||||
import glob
|
import glob
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -7,29 +6,20 @@ import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import ffmpy
|
import ffmpy
|
||||||
|
video_extensions = ['webm', 'mp4', 'mkv', 'gif', 'mov']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VideoCut:
|
class VideoCut:
|
||||||
"""FFMPEG视频剪辑 -- !有卡顿问题 暂废弃"""
|
"""FFMPEG视频剪辑"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
return {
|
return {
|
||||||
"required": {
|
"required": {
|
||||||
"config": ("STRING",),
|
"video_path": ("STRING",{"placeholder": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
|
||||||
"video_path": ("STRING",),
|
"start": ("STRING", {"default": "00:00:00"}),
|
||||||
"mod": ("INT",),
|
"end": ("STRING", {"default": "00:00:10"}),
|
||||||
"fps": ("FLOAT",),
|
|
||||||
"period_length": (
|
|
||||||
"INT",
|
|
||||||
{
|
|
||||||
"default": 10,
|
|
||||||
"min": 4,
|
|
||||||
"max": 100,
|
|
||||||
"step": 1,
|
|
||||||
"forceInput": True,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,16 +32,9 @@ class VideoCut:
|
||||||
|
|
||||||
CATEGORY = "不忘科技-自定义节点🚩"
|
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])
|
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
|
# 新文件名 复制改名适配ffmpeg
|
||||||
uid = uuid.uuid1()
|
uid = uuid.uuid1()
|
||||||
temp_fname = os.sep.join(
|
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],
|
||||||
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],
|
video_path.split(os.sep)[-1].split(".")[-1],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
@ -83,23 +66,17 @@ class VideoCut:
|
||||||
)
|
)
|
||||||
# 调用ffmpeg
|
# 调用ffmpeg
|
||||||
ff = ffmpy.FFmpeg(
|
ff = ffmpy.FFmpeg(
|
||||||
inputs={video_path: ["-accurate_seek"]},
|
inputs={video_path: None},
|
||||||
outputs={
|
outputs={
|
||||||
output: [
|
output: [
|
||||||
"-f",
|
|
||||||
"segment",
|
|
||||||
"-ss",
|
"-ss",
|
||||||
str(round(start * mul, 3)),
|
start,
|
||||||
"-to",
|
"-to",
|
||||||
str(round(end * mul, 3)),
|
end,
|
||||||
"-segment_times",
|
"-c:v",
|
||||||
str(period_length),
|
"libx264",
|
||||||
"-c",
|
"-c:a",
|
||||||
"copy",
|
"copy"
|
||||||
"-map",
|
|
||||||
"0",
|
|
||||||
"-avoid_negative_ts",
|
|
||||||
"1",
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ opencv-python
|
||||||
ultralytics
|
ultralytics
|
||||||
cos-python-sdk-v5
|
cos-python-sdk-v5
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
|
tencentcloud-sdk-python
|
||||||
Loading…
Reference in New Issue