moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

ImageSequenceClip doesn't create a video with transparent background even though the images have transparent background.

Open emiliolopez95 opened this issue 3 years ago • 1 comments

Expected Behavior

I am creating a video using moviepy ImageSequenceClip. The input are the images found on this link: https://drive.google.com/drive/folders/1hQ3pfGPMvDAijS4IUcbu5hVy_HmrfCOh?usp=sharing.

All the images are png and have some pixels with the alpha channel set to 0 (the background is transparent).

The created video should keep those background pixels with alpha channel set to 0 (the video background should be transparent).

Actual Behavior

The created video is not transparent. The background pixels show their RGB values.

Steps to Reproduce the Problem

"images" folder should contain this images: https://drive.google.com/drive/folders/1hQ3pfGPMvDAijS4IUcbu5hVy_HmrfCOh?usp=sharing.

import moviepy.editor as mpy

clip = mpy.ImageSequenceClip("images", fps=24, with_mask=True)
clip.set_opacity(0)
clip.write_videofile("video_test.mp4")

Specifications

  • Python Version: 3.7
  • Moviepy Version: 1.0.3
  • Platform Name: MacOS Catalina
  • Platform Version: 10.15.6

I also tried it with Docker using this image and the issue was still there: tiangolo/uvicorn-gunicorn-fastapi:python3.7

emiliolopez95 avatar Aug 19 '20 18:08 emiliolopez95

This uses libx264 (H.264) codec by default, which does not support alpha channel (transparency). You need to use codec that supports it, however unfortunately there seems to be a big problem regarding that in moviepy. You'll be better of to render that sequence as an image sequence (literally one frame = ona image) and then put it together using ffmpeg. https://www.digitalrebellion.com/blog/posts/list_of_video_formats_supporting_alpha_channels.html

ApplePie420 avatar Apr 19 '22 15:04 ApplePie420

Linking to #104, which is also about problems with transparency.

keikoro avatar Oct 11 '22 03:10 keikoro