moviepy
moviepy copied to clipboard
Problems with exporting transparent video
Overview of the problem
Hello,I'm using the code below, to export a transparent video with alpha, I've tried avi, Tested with Adobe After Effects, neither is a transparent video.
file used: 01.png input3.mov
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")
try other methods
Then somewhere in https://github.com/Zulko/moviepy/issues/1502 I've found a way to do it - render 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. ↓↓↓
I don't know if there is any other way to get the transparent video directly, if you know, please let me know, thanks a lot.
Would appreciate a reply, even if it is a negative one. Thanks a lot for the wonderful work with this package.
Transparent video or picture sequence with alpha but no black border, would like to get one of these, thanks again.🙏
I modified the footage and code to make the video and I ended up with a transparent video.
This is the transparent image material used to make the video. After exporting the transparent sequence image, there will be a black border, so this method is not used.
change ideas:
Make each transparent image a white background image and a grayscale information image converted from alpha.
Make a video twice with different image assets, then use Adobe Premiere's keying feature to make a transparent video.
The final effect is as follows:
https://user-images.githubusercontent.com/10295975/189846227-9fbeadff-5c33-452b-8051-3e2dd72b5144.mp4
This method has limitations and is not suitable for all situations.
I hope to fix the problem of the black border, so that the transparent image sequence can be directly obtained. Thank you all for your contributions.