[Python] Overlay effect no working as expected in moviepy

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to apply overlay effect (mp4 with black background) and the black color is not completely removed using the mask below

    from moviepy.editor import VideoFileClip, CompositeVideoClip
    from moviepy.video.fx.all import mask_color

    # Load the base video and overlay video
    base_clip = VideoFileClip("bed_time/testing/output.mp4")
    overlay_clip = VideoFileClip("overlay/border_video.mp4")

    # Resize overlay (optional, if needed)
    overlay_clip = overlay_clip.resize(height=base_clip.h)
    overlay_clip = overlay_clip.set_duration(base_clip.duration)

    # Mask the black background in the overlay video
    overlay_masked = mask_color(overlay_clip, color=[0, 0, 0])

    # Position the overlay on top of the base video
    # (change `pos` to adjust overlay position)
    composited_clip = CompositeVideoClip([base_clip, overlay_masked.set_position(("center", "center"))])

    # Write the final video to file
    composited_clip.write_videofile("output_video.mp4", codec="libx264", fps=24)


    On the right hand side is what I'm trying to achieve and on the left the broken overlay effect I'm getting with code above. Any thoughts?

    [​IMG]

    Continue reading...

Compartilhe esta Página