利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(video): keep alpha masks aligned during zoom transitions
Rudy Celekli1b5c182a9270
diff --git a/app/services/utils/video_effects.py b/app/services/utils/video_effects.pyindex 72b57d7d..7576fa2e 100644--- a/app/services/utils/video_effects.py+++ b/app/services/utils/video_effects.py@@ -128,7 +128,7 @@ def zoomin_transition(clip: Clip, t: float) -> Clip:scale_factor = 1 + (_ZOOM_MAX_SCALE - 1) * progressreturn _zoom_frame(get_frame(current_time), scale_factor)- return clip.transform(scale_effect)+ return clip.transform(scale_effect, apply_to=["mask"])def zoomout_transition(clip: Clip, t: float) -> Clip:@@ -142,4 +142,4 @@ def zoomout_transition(clip: Clip, t: float) -> Clip:scale_factor = _ZOOM_MAX_SCALE - (_ZOOM_MAX_SCALE - 1) * progressreturn _zoom_frame(get_frame(current_time), scale_factor)- return clip.transform(scale_effect)+ return clip.transform(scale_effect, apply_to=["mask"])diff --git a/test/services/test_zoom_alpha_alignment.py b/test/services/test_zoom_alpha_alignment.pynew file mode 100644index 00000000..06104dd9--- /dev/null+++ b/test/services/test_zoom_alpha_alignment.py@@ -0,0 +1,38 @@+import numpy as np+import pytest+from moviepy import ColorClip, CompositeVideoClip, ImageClip+from app.services.utils import video_effects++[email protected]('effect,time', [(video_effects.zoomin_transition, 1.99), (video_effects.zoomout_transition, 0)])+def test_transparent_subject_mask_moves_with_zoomed_color(effect, time):+ pixels = np.zeros((100, 100, 4), dtype=np.uint8)+ pixels[:, :, :3] = 255+ pixels[35:65, 35:65, 3] = 255+ source = ImageClip(pixels).with_duration(2)+ transformed = effect(source, 1)+ background = ColorClip((100, 100), color=(0, 0, 0)).with_duration(2)+ composed = CompositeVideoClip([background, transformed])+ try:+ frame = composed.get_frame(time)+ # A20% zoom moves the subject's left edge35->32: atx33 the+ # transformed subject should now be visible over the black canvas.+ assert frame[50, 33, 0] > 150+ assert frame[50, 20, 0] == 0+ assert frame[50, 50, 0] == 255+ finally:+ composed.close()+ background.close()+ transformed.close()+ source.close()+++def test_opaque_video_zoom_keeps_dimensions_and_center():+ source = ImageClip(np.full((100, 100, 3), (220, 10, 30), dtype=np.uint8)).with_duration(2)+ transformed = video_effects.zoomin_transition(source, 1)+ try:+ assert transformed.get_frame(1).shape == (100, 100, 3)+ assert tuple(transformed.get_frame(1)[50, 50]) == (220, 10, 30)+ finally:+ transformed.close()+ source.close()