I'm trying to create a transparent video with alpha.
This is my code:
import moviepy.editor as mpe
clip = mpe.VideoFileClip("input3.mov")
mask = mpe.ImageClip("01.png", ismask=True, fromalpha=True).to_mask()
clip = clip.set_mask(mask)
final_clip = mpe.CompositeVideoClip([clip])
final_clip.write_videofile("output1.avi", codec="rawvideo")
files used:
The output is not transparent (tested with Adobe After Effects).
After reading https://github.com/Zulko/moviepy/issues/1502 I found a way to do it - by rendering the clip as a sequence of images, I end up with a sequence of images with alpha. Although it is not a transparent video, but a transparent picture sequence, I can also accept it, but it needs to be reprocessed.
import moviepy.editor as mpe
clip = mpe.VideoFileClip("input3.mov")
mask = mpe.ImageClip("01.png", ismask=True, fromalpha=True).to_mask()
clip = clip.set_mask(mask)
final_clip = mpe.CompositeVideoClip([clip])
final_clip.write_images_sequence('00/frame%05d.png', fps=25, withmask=True, logger='bar')
But there is a little problem, there is a black border around the edge of the picture. ↓↓↓
I guess it may be the effect of the default black background. After I changed the background color, I found that the exported image sequence lost alpha, which is not the result I wanted.
import moviepy.editor as mpe
clip = mpe.VideoFileClip("input3.mov")
mask = mpe.ImageClip("01.png", ismask=True, fromalpha=True).to_mask()
clip = clip.set_mask(mask)
final_clip = mpe.CompositeVideoClip([clip], bg_color=(255, 255, 255))
final_clip.write_images_sequence('00/frame%05d.png', fps=25, withmask=True, logger='bar')
White background image with missing alpha. ↓↓↓
How else can get the transparent video directly?


