利用 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): flatten image opacity onto the MP4 canvas
Rudy Celekli0a41c6160771
diff --git a/app/services/video.py b/app/services/video.pyindex aeee9cb8..d131b3b6 100644--- a/app/services/video.py+++ b/app/services/video.py@@ -748,7 +748,8 @@ def _sanitize_image_file(image_path: str) -> str:def _open_image_clip_with_fallback(image_path: str):# MoviePy does not apply camera EXIF orientation while decoding an image.- # CMYK JPEG channels also must become RGB rather than an apparent alpha mask.+ # CMYK JPEG channels must become RGB; LA must become RGBA so MoviePy+ # creates a proper opacity mask rather than treating alpha as a color band.# Ordinary RGB inputs retain the direct path.try:with Image.open(image_path) as image:@@ -757,7 +758,7 @@ def _open_image_clip_with_fallback(image_path: str):except Exception:orientation = 1image_mode = None- if orientation in range(2, 9) or image_mode == "CMYK":+ if orientation in range(2, 9) or image_mode in {"CMYK", "LA"}:sanitized_path = _sanitize_image_file(image_path)return ImageClip(sanitized_path), sanitized_path@@ -1884,7 +1885,7 @@ def render_image_zoom_video(image_path: str, clip_duration: int = 5) -> str:# Optionally, create a composite video clip containing the zoomed clip.# This is useful if you want to add other elements to the video.- final_clip = CompositeVideoClip([zoom_clip])+ final_clip = CompositeVideoClip([zoom_clip], bg_color=(0, 0, 0))try:# The duration changes the rendered content, so it must be part of# the output identity. Different tasks may render the same imagediff --git a/test/services/test_image_gray_alpha_composition.py b/test/services/test_image_gray_alpha_composition.pynew file mode 100644index 00000000..1a9656d9--- /dev/null+++ b/test/services/test_image_gray_alpha_composition.py@@ -0,0 +1,19 @@+import pytest+from PIL import Image+from moviepy import VideoFileClip++from app.services.video import close_clip, render_image_zoom_video++[email protected]("mode,pixel", [("LA", (180, 128)), ("RGBA", (180, 180, 180, 128))])+def test_alpha_image_preserves_partial_opacity_in_native_render(tmp_path, mode, pixel):+ source = tmp_path / "gray-alpha.png"+ Image.new(mode, (32, 32), pixel).save(source)+ output = render_image_zoom_video(str(source), 0.1)+ clip = VideoFileClip(output, audio=False)+ try:+ pixel = clip.get_frame(0)[16, 16]+ # Half-opacity gray180 over the renderer's black canvas is gray90.+ assert all(abs(int(channel) - 90) <= 5 for channel in pixel)+ finally:+ close_clip(clip)diff --git a/test/services/test_video.py b/test/services/test_video.pyindex 97c0d0d0..aa89c42f 100644--- a/test/services/test_video.py+++ b/test/services/test_video.py@@ -572,7 +572,7 @@ class TestVideoService(unittest.TestCase):return selfclass FakeCompositeClip:- def __init__(self, clips):+ def __init__(self, clips, bg_color=None):self.duration = clips[0].durationdef write_videofile(self, output, **_kwargs):@@ -612,7 +612,7 @@ class TestVideoService(unittest.TestCase):writes = 0class FakeCompositeClip:- def __init__(self, _clips):+ def __init__(self, _clips, bg_color=None):passdef write_videofile(self, output, **_kwargs):