From 5282e58a10be320a3ec0736678b8a93239cca3a0 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 20 Jul 2025 16:01:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81zoom=5Fcut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/ffmpeg.py | 2 ++ entity/ffmpeg.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/biz/ffmpeg.py b/biz/ffmpeg.py index f1a9182..2d57d5e 100644 --- a/biz/ffmpeg.py +++ b/biz/ffmpeg.py @@ -50,6 +50,7 @@ def parse_ffmpeg_task(task_info, template_info): sub_ffmpeg_task.ext_data = ext_data or {} sub_ffmpeg_task.frame_rate = template_info.get("frame_rate", 25) sub_ffmpeg_task.center_cut = part.get("crop_mode", None) + sub_ffmpeg_task.zoom_cut = part.get("zoom_cut", None) for effect in part.get('effects', []): sub_ffmpeg_task.add_effect(effect) for lut in part.get('filters', []): @@ -64,6 +65,7 @@ def parse_ffmpeg_task(task_info, template_info): task.resolution = template_info.get("video_size", "") overall = template_info.get("overall_template") task.center_cut = template_info.get("crop_mode", None) + task.zoom_cut = template_info.get("zoom_cut", None) task.frame_rate = template_info.get("frame_rate", 25) # if overall.get('source', ''): # source, ext_data = parse_video(overall.get('source'), task_params, template_info) diff --git a/entity/ffmpeg.py b/entity/ffmpeg.py index 0fd3a63..54b4646 100644 --- a/entity/ffmpeg.py +++ b/entity/ffmpeg.py @@ -187,6 +187,32 @@ class FfmpegTask(object): filter_args.append(f"{video_output_str}crop=x={_x}:y=0:w=ih*ih/iw:h=ih[v_cut{effect_index}]") video_output_str = f"[v_cut{effect_index}]" effect_index += 1 + if self.zoom_cut == 1 and self.resolution: + _input = None + for input_file in self.input_file: + if type(input_file) is str: + _input = input_file + break + elif isinstance(input_file, FfmpegTask): + _input = input_file.get_output_file() + break + if _input: + from util.ffmpeg import probe_video_info + _iw, _ih, _ = probe_video_info(_input) + _w, _h = self.resolution.split('x', 1) + pos_json_str = self.ext_data.get('posJson', '{}') + pos_json = json.loads(pos_json_str) + _v_w = pos_json.get('imgWidth', 1) + _v_h = pos_json.get('imgHeight', 1) + _f_x = pos_json.get('ltX', 0) + _f_x2 = pos_json.get('rbX', 0) + _f_y = pos_json.get('ltY', 0) + _f_y2 = pos_json.get('rbY', 0) + _x = min(max(0, (_f_x + _f_x2) / 2 - int(_w) / 2), _iw - int(_w)) + _y = min(max(0, (_f_y + _f_y2) / 2 - int(_h) / 2), _ih - int(_h)) + filter_args.append(f"{video_output_str}crop=x={_x}:y={_y}:w={_w}:h={_h}[vz_cut{effect_index}]") + video_output_str = f"[vz_cut{effect_index}]" + effect_index += 1 for effect in self.effects: if effect.startswith("cameraShot:"): param = effect.split(":", 2)[1]