You've already forked FrameTour-RenderWorker
fix(video): 修复视频定格效果实现逻辑
- 修改cameraShot实现注释,明确标注定格效果功能 - 使用tpad代替freezeframes实现更准确的定格效果 - 更新滤镜链参数配置,确保定格时长正确应用 - 优化变量命名,提高代码可读性 - 调整concat拼接输入源,确保视频流正确连接
This commit is contained in:
@@ -547,15 +547,16 @@ class RenderSegmentVideoHandler(BaseHandler):
|
|||||||
if start_sec <= 0 or duration_sec <= 0:
|
if start_sec <= 0 or duration_sec <= 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# cameraShot 实现:
|
# cameraShot 实现(定格效果):
|
||||||
# 1. fps + split 分割
|
# 1. fps + split 分割
|
||||||
# 2. 第一路:trim(0, start+duration) + freezeframes
|
# 2. 第一路:trim(0, start) + tpad冻结duration秒
|
||||||
# 3. 第二路:trim(start, end)
|
# 3. 第二路:trim(start, end)
|
||||||
# 4. concat 拼接
|
# 4. concat 拼接
|
||||||
|
|
||||||
start_frame = start_sec * fps
|
|
||||||
split_out_a = f'[eff{effect_idx}_a]'
|
split_out_a = f'[eff{effect_idx}_a]'
|
||||||
split_out_b = f'[eff{effect_idx}_b]'
|
split_out_b = f'[eff{effect_idx}_b]'
|
||||||
|
frozen_out = f'[eff{effect_idx}_frozen]'
|
||||||
|
rest_out = f'[eff{effect_idx}_rest]'
|
||||||
effect_output = f'[v_eff{effect_idx}]'
|
effect_output = f'[v_eff{effect_idx}]'
|
||||||
|
|
||||||
# fps + split
|
# fps + split
|
||||||
@@ -563,24 +564,21 @@ class RenderSegmentVideoHandler(BaseHandler):
|
|||||||
f"{current_output}fps=fps={fps},split{split_out_a}{split_out_b}"
|
f"{current_output}fps=fps={fps},split{split_out_a}{split_out_b}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 第一路:trim + freezeframes(在 start 帧处冻结 duration 秒)
|
# 第一路:trim(0, start) + tpad冻结
|
||||||
# freezeframes: 从 first 帧开始,用 replace 帧替换后续帧
|
# tpad=stop_mode=clone 将最后一帧冻结指定时长
|
||||||
# 这样实现定格效果:在 start_frame 位置冻结
|
|
||||||
filter_parts.append(
|
filter_parts.append(
|
||||||
f"{split_out_a}trim=start=0:end={start_sec + duration_sec},"
|
f"{split_out_a}trim=start=0:end={start_sec},setpts=PTS-STARTPTS,"
|
||||||
f"setpts=PTS-STARTPTS,"
|
f"tpad=stop_mode=clone:stop_duration={duration_sec}{frozen_out}"
|
||||||
f"freezeframes=first={start_frame}:last={start_frame + duration_sec * fps - 1}:replace={start_frame}"
|
|
||||||
f"{split_out_a}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 第二路:trim 从 start 开始
|
# 第二路:trim 从 start 开始
|
||||||
filter_parts.append(
|
filter_parts.append(
|
||||||
f"{split_out_b}trim=start={start_sec},setpts=PTS-STARTPTS{split_out_b}"
|
f"{split_out_b}trim=start={start_sec},setpts=PTS-STARTPTS{rest_out}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# concat 拼接
|
# concat 拼接
|
||||||
filter_parts.append(
|
filter_parts.append(
|
||||||
f"{split_out_a}{split_out_b}concat=n=2:v=1:a=0{effect_output}"
|
f"{frozen_out}{rest_out}concat=n=2:v=1:a=0{effect_output}"
|
||||||
)
|
)
|
||||||
|
|
||||||
current_output = effect_output
|
current_output = effect_output
|
||||||
|
|||||||
Reference in New Issue
Block a user