From 67696739f9f172dd786bcc1f655f5f7ff2e3a607 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 27 Feb 2025 14:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E5=89=B2=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/ffmpeg.py | 1 + entity/ffmpeg.py | 20 ++++++++++++++++++-- util/api.py | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/biz/ffmpeg.py b/biz/ffmpeg.py index 047db41..b58c86a 100644 --- a/biz/ffmpeg.py +++ b/biz/ffmpeg.py @@ -38,6 +38,7 @@ def parse_ffmpeg_task(task_info, template_info): output_file = "out_" + str(time.time()) + ".mp4" task = FfmpegTask(tasks, output_file=output_file) overall = template_info.get("overall_template") + task.center_cut = template_info.get("crop_mode", None) task.frame_rate = template_info.get("frame_rate", 25) if overall.get('source', ''): source = parse_video(overall.get('source'), task_params, template_info) diff --git a/entity/ffmpeg.py b/entity/ffmpeg.py index 4d22331..61a7879 100644 --- a/entity/ffmpeg.py +++ b/entity/ffmpeg.py @@ -14,6 +14,9 @@ class FfmpegTask(object): self.input_file = input_file else: self.input_file = [] + self.zoom_cut = None + self.center_cut = None + self.ext_data = {} self.task_type = task_type self.output_file = output_file self.mute = True @@ -101,6 +104,10 @@ class FfmpegTask(object): return False if self.speed != 1: return False + if self.zoom_cut is not None: + return False + if self.center_cut is not None: + return False return True def check_can_copy(self): @@ -116,6 +123,10 @@ class FfmpegTask(object): return False if len(self.input_file) > 1: return False + if self.zoom_cut is not None: + return False + if self.center_cut is not None: + return False return True def check_audio_track(self): @@ -134,7 +145,6 @@ class FfmpegTask(object): output_args.append("h264_mp4toannexb") video_output_str = "[0:v]" audio_output_str = "[0:v]" - video_input_count = 0 audio_input_count = 0 for input_file in self.input_file: input_args.append("-i") @@ -142,8 +152,14 @@ class FfmpegTask(object): input_args.append(input_file) elif isinstance(input_file, FfmpegTask): input_args.append(input_file.get_output_file()) + if self.center_cut == 1: + pos_json = self.ext_data.get('posJson', {}) + _v_w = pos_json.get('imgWidth', 1) + _f_x = pos_json.get('ltX', 0) + _x = f'{float(_f_x/_v_w) :.5f}*iw' + filter_args.append(f"[{video_output_str}]crop=x={_x}:y=0:w=ih*ih/iw:h=ih[{video_output_str}]") for lut in self.luts: - filter_args.append("[0:v]lut3d=file=" + lut + "[0:v]") + filter_args.append(f"[{video_output_str}]lut3d=file={lut}[{video_output_str}]") for overlay in self.overlays: input_index = input_args.count("-i") input_args.append("-i") diff --git a/util/api.py b/util/api.py index 8a55a93..f264490 100644 --- a/util/api.py +++ b/util/api.py @@ -90,6 +90,7 @@ def get_template_info(template_id): # 占位符 _template['source'] = "PLACEHOLDER_" + template_info.get('sourceUrl', '') _template['mute'] = template_info.get('mute', True) + _template['crop_mode'] = template_info.get('cropEnable', None) else: _template['source'] = None _overlays = template_info.get('overlays', '')