This commit is contained in:
liubiren 2026-02-11 21:52:01 +08:00
parent 33f8edcd86
commit 16bc398f39
2 changed files with 17 additions and 19 deletions

View File

@ -31,9 +31,8 @@ class JianYingExport:
def __init__( def __init__(
self, self,
materials_folder_path: str, materials_folder_path: str,
program_path: str = "E:\\JianYingPro\\5.9.0.11632\\JianYingPro.exe", # 仅可在windows运行该脚本 program_path: str = r"E:\JianYingPro\5.9.0.11632\JianYingPro.exe", # 仅可在windows运行该脚本
drafts_folder_path: str = "E:\\JianYingPro Drafts", drafts_folder_path: str = r"E:\JianYingPro Drafts",
draft_counts: int = 10,
video_width: int = 1080, video_width: int = 1080,
video_height: int = 1920, video_height: int = 1920,
video_fps: int = 30, video_fps: int = 30,
@ -43,7 +42,6 @@ class JianYingExport:
:param program_path: 剪映程序路径 :param program_path: 剪映程序路径
:param drafts_folder_path: 剪映草稿文件夹路径 :param drafts_folder_path: 剪映草稿文件夹路径
:param materials_folder_path: 素材文件夹路径 :param materials_folder_path: 素材文件夹路径
:param draft_counts: 草稿数默认为 10
:param video_width: 视频宽度默认为 1080像素 :param video_width: 视频宽度默认为 1080像素
:param video_height: 视频高度默认为 1920像素 :param video_height: 视频高度默认为 1920像素
:param video_fps: 视频帧率单位为帧/默认为 30 :param video_fps: 视频帧率单位为帧/默认为 30
@ -301,7 +299,6 @@ class JianYingExport:
self.video_width, self.video_height = video_width, video_height self.video_width, self.video_height = video_width, video_height
self.video_fps = video_fps self.video_fps = video_fps
self.draft_counts = draft_counts
# 初始化所有草稿名称 # 初始化所有草稿名称
self.draft_names = [] self.draft_names = []
@ -409,22 +406,21 @@ class JianYingExport:
else: else:
self.materials["statement_video_material_path"] = [] self.materials["statement_video_material_path"] = []
def export(self, workflow_name: str = "0001", batch_draft_counts: int = 1): def export_videos(self, workflow: str, draft_counts: int):
""" """
导出草稿 导出视频
:param workflow_name: 工作流名称 :param workflow: 工作流名称
:param batch_draft_counts: 每批次导出草稿数 :param draft_counts: 每批次导出草稿数
""" """
if workflow_name not in self.workflows: if workflow not in self.workflows:
raise RuntimeError(f"未配置该工作流") raise RuntimeError(f"未配置该工作流")
self.workflow = self.workflows[workflow_name] self.workflow = self.workflows[workflow]
# 若工作流包含添加背景音频则将添加背景视频工作配置中播放音量设置为0 # 若工作流包含添加背景音频则将添加背景视频工作配置中播放音量设置为0
if "add_background_audio" in self.workflow: if "add_background_audio" in self.workflow:
self.configuration["add_background_video"]["volume"] = [0.0] self.configuration["add_background_video"]["volume"] = [0.0]
# 按照工作流和工作配置拼接素材,批量生成草稿 # 按照工作流和工作配置拼接素材,批量生成草稿
self._generate_drafts() self._generate_drafts(draft_counts=draft_counts)
# 批次导出 # 批次导出
for batch_start in range(0, self.draft_counts, batch_draft_counts): for batch_start in range(0, self.draft_counts, batch_draft_counts):
@ -464,15 +460,17 @@ class JianYingExport:
def _generate_drafts( def _generate_drafts(
self, self,
draft_counts: int,
) -> None: ) -> None:
""" """
按照工作流和工作配置拼接素材批量生成草稿 按照工作流和工作配置拼接素材批量生成草稿
:param draft_counts: 草稿数
:return: :return:
""" """
for idx in range(self.draft_counts): for idx in range(1, draft_counts + 1):
# 构建草稿名称 # 构建草稿名称
draft_name = self.project_name + f"{idx + 1:03d}" draft_name = self.project_name + f"{idx:03d}"
print(f"正在合成短视频 {draft_name} {idx + 1}/{self.draft_counts}...") print(f"正在合成短视频 {draft_name} {idx}/{draft_counts}...")
# 实例化 JianYingDraft # 实例化 JianYingDraft
draft = JianYingDraft( draft = JianYingDraft(

View File

@ -9,8 +9,8 @@ if __name__ == "__main__":
# 实例化 JianYingExport # 实例化 JianYingExport
jianying_export = JianYingExport( jianying_export = JianYingExport(
materials_folder_path=r"E:\jianying\materials\淘宝闪购模版001", materials_folder_path=r"E:\jianying\materials\淘宝闪购模版001",
draft_counts=1, draft_counts=10,
) )
# 导出草稿 # 导出视频
jianying_export.export(workflow_name="0001") jianying_export.export_videos(workflow_name="0001")