Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.07k stars 1.51k forks source link

Difficulty Achieving Transparent Background in .webm Files with CompositeVideoClip #2109

Open sultanpeyek opened 4 months ago

sultanpeyek commented 4 months ago

Expected Behavior

I expect to generate a .webm file with a transparent background using CompositeVideoClip by setting bg_color=(0, 0, 0, 0) and specifying the appropriate ffmpeg_params to handle transparency.

Actual Behavior

All input .mov files are confirmed to have alpha channels and are successfully layered in the correct order when combined using CompositeVideoClip. Despite this, the final .webm output generated from these composited .mov files results in an unwanted black background.

Steps to Reproduce the Problem

from moviepy.editor import VideoFileClip, CompositeVideoClip

def convert_mov_to_webm(input_files, output_file):
    clips = [VideoFileClip(f, has_mask=True) for f in input_files]
    composite = CompositeVideoClip(clips, bg_color=(0, 0, 0, 0))
    composite.write_videofile(output_file, codec='libvpx-vp9', audio_codec=None,
                              fps=composite.fps, ffmpeg_params=['-pix_fmt', 'yuva420p'])

# Usage
input_files = [
    "./1.mov",
    "./2.mov",
    "./3.mov"
]
output_file = "./output.webm"
convert_mov_to_webm(input_files, output_file)

Specifications