From 51e7d21f84d0860f88880636384112799dff3497 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 7 Aug 2025 14:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=A7=E8=B7=B3=E8=BF=87=E3=80=81zoom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/ffmpeg.py | 50 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/entity/ffmpeg.py b/entity/ffmpeg.py index db3de13..3cb9921 100644 --- a/entity/ffmpeg.py +++ b/entity/ffmpeg.py @@ -246,12 +246,13 @@ class FfmpegTask(object): _mid_out_str = "[eff_m]" _end_out_str = "[eff_e]" filter_args.append(f"{video_output_str}split=3{_start_out_str}{_mid_out_str}{_end_out_str}") - filter_args.append(f"{_start_out_str}select=lt(n\\,{int(start*self.frame_rate)}){_start_out_str}") - filter_args.append(f"{_end_out_str}select=gt(n\\,{int(start*self.frame_rate)}){_end_out_str}") - filter_args.append(f"{_mid_out_str}select=eq(n\\,{int(start*self.frame_rate)}){_mid_out_str}") - filter_args.append(f"{_mid_out_str}tpad=start_mode=clone:start_duration={duration:.4f}{_mid_out_str}") + filter_args.append(f"{_start_out_str}select=lt(n\\,{int(start * self.frame_rate)}){_start_out_str}") + filter_args.append(f"{_end_out_str}select=gt(n\\,{int(start * self.frame_rate)}){_end_out_str}") + filter_args.append(f"{_mid_out_str}select=eq(n\\,{int(start * self.frame_rate)}){_mid_out_str}") + filter_args.append( + f"{_mid_out_str}tpad=start_mode=clone:start_duration={duration:.4f}{_mid_out_str}") if rotate_deg != 0: - filter_args.append(f"{_mid_out_str}rotate=PI*{rotate_deg}/360{_mid_out_str}") + filter_args.append(f"{_mid_out_str}rotate=PI*{rotate_deg}/180{_mid_out_str}") # filter_args.append(f"{video_output_str}trim=start=0:end={start+duration},tpad=stop_mode=clone:stop_duration={duration},setpts=PTS-STARTPTS{_start_out_str}") # filter_args.append(f"tpad=start_mode=clone:start_duration={duration},setpts=PTS-STARTPTS{_start_out_str}") # filter_args.append(f"{_end_out_str}trim=start={start}{_end_out_str}") @@ -269,7 +270,44 @@ class FfmpegTask(object): filter_args.append(f"{video_output_str}setpts={param}*PTS[v_eff{effect_index}]") video_output_str = f"[v_eff{effect_index}]" elif effect.startswith("zoom:"): - ... + param = effect.split(":", 2)[1] + if param == '': + continue + _split = param.split(",") + if len(_split) < 3: + continue + try: + start_time = float(_split[0]) + zoom_factor = float(_split[1]) + duration = float(_split[2]) + if start_time < 0: + start_time = 0 + if duration < 0: + duration = 0 + if zoom_factor <= 0: + zoom_factor = 1 + except (ValueError, IndexError): + start_time = 0 + duration = 0 + zoom_factor = 1 + if zoom_factor == 1: + continue + effect_index += 1 + if duration == 0: + filter_args.append(f"{video_output_str}trim=start={start_time},scale=iw*{zoom_factor}:ih*{zoom_factor},crop=iw/{zoom_factor}:ih/{zoom_factor}:(iw-iw/{zoom_factor})/2:(ih-ih/{zoom_factor})/2,setpts=PTS-STARTPTS[v_eff{effect_index}]") + else: + zoom_expr = f"if(between(t,{start_time},{start_time + duration}),{zoom_factor},1)" + filter_args.append(f"{video_output_str}scale=iw*({zoom_expr}):ih*({zoom_expr}),crop=iw:ih:(iw-iw)/2:(ih-ih)/2[v_eff{effect_index}]") + video_output_str = f"[v_eff{effect_index}]" + elif effect.startswith("skip:"): + param = effect.split(":", 2)[1] + if param == '': + param = "0" + skip_seconds = float(param) + if skip_seconds > 0: + effect_index += 1 + filter_args.append(f"{video_output_str}trim=start={skip_seconds},setpts=PTS-STARTPTS[v_eff{effect_index}]") + video_output_str = f"[v_eff{effect_index}]" ... if self.resolution: filter_args.append(f"{video_output_str}scale={self.resolution.replace('x', ':')}[v]")