From 94373cee720cedceaf1ceb9c2defda862ce4144a Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 5 Mar 2025 12:16:10 +0800 Subject: [PATCH] =?UTF-8?q?cameraShot=E7=89=B9=E6=95=88=E5=8F=8A=E6=97=8B?= =?UTF-8?q?=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/ffmpeg.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/entity/ffmpeg.py b/entity/ffmpeg.py index 192f6dd..a3b5326 100644 --- a/entity/ffmpeg.py +++ b/entity/ffmpeg.py @@ -185,22 +185,36 @@ class FfmpegTask(object): if effect.startswith("cameraShot:"): param = effect.split(":", 2)[1] if param == '': - param = "3,1" + param = "3,1,0" _split = param.split(",") start = 3 duration = 1 + rotate_deg = 0 + if len(_split) >= 3: + if _split[2] == '': + rotate_deg = 0 + else: + rotate_deg = int(_split[2]) if len(_split) >= 2: - start = int(_split[0]) - duration = int(_split[1]) - elif len(_split) == 1: - start = int(_split[0]) + duration = float(_split[1]) + if len(_split) >= 1: + start = float(_split[0]) _start_out_str = "[eff_s]" + _mid_out_str = "[eff_m]" _end_out_str = "[eff_e]" - filter_args.append(f"{video_output_str}fps=fps={self.frame_rate},split{_start_out_str}{_end_out_str}") - filter_args.append(f"{_start_out_str}trim=start={0}:end={start+duration},freezeframes=first={start*self.frame_rate}:replace={start*self.frame_rate}{_start_out_str}") - filter_args.append(f"{_end_out_str}trim=start={start}{_end_out_str}") + filter_args.append(f"{video_output_str}split=3{_start_out_str}{_mid_out_str}{_end_out_str}") + filter_args.append(f"{video_output_str}[0:v]select=lt(n\,{int(start*self.frame_rate)}){_start_out_str}") + filter_args.append(f"{video_output_str}[0:v]select=gt(n\,{int(start*self.frame_rate)}){_end_out_str}") + filter_args.append(f"{video_output_str}[0:v]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"{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}") video_output_str = "[v_eff]" - filter_args.append(f"{_start_out_str}{_end_out_str}concat=n=2:v=1:a=0{video_output_str}") + # filter_args.append(f"{_end_out_str}{_start_out_str}overlay=eof_action=pass{video_output_str}") + filter_args.append(f"{_start_out_str}{_mid_out_str}{_end_out_str}concat=n=3:v=1:a=0,setpts=N/{self.frame_rate}/TB{video_output_str}") elif effect.startswith("zoom:"): ... ...