moviepy
moviepy copied to clipboard
How to preserve transparent mask layers in exported videos
Expected Behavior
My original video was in mov format with Alpha channels, but the transparent channels were lost after exporting. I can use ffmpeg to export, It is normal :
ffmpeg -i test.mov -vf "scale=640:-1:flags=lanczos" -c:v qtrle out_test.mov
Actual Behavior
Steps to Reproduce the Problem
# 加载带透明通道的视频
alpha_video_clip = VideoFileClip("/Users/kangkang/Downloads/videos/test.mov",has_mask=True)
alpha_video_clip = alpha_video_clip.resize((720,1080))
# 导出视频丢失了透明度
alpha_video_clip.write_videofile("out_test.mov", codec='qtrle', threads=8,audio_codec='aac')
# ffmpeg命令导出正常
# ffmpeg -i test.mov -vf "scale=640:-1:flags=lanczos" -c:v qtrle out_test.mov
Specifications
- Python Version: 3.10
- MoviePy Version: 1.0.3
- Platform Name: macos
- Platform Version: 15
Do You know how to get the transparent video.
Do You know how to get the transparent video.
According to my test, Moviepy does not support loading and exporting a transparent video as another transparent video. You can use ffmpeg to complete this task
Could You Give the Example Commands for the FFMPEG.
Could You Give the Example Commands for the FFMPEG.
- Pngs to transparent video (png files : image000001.png .... image000xxx.png)
ffmpeg -i ./pngs/image%06d.png -i ./audio/f3ab7be97c98a6abca9723a8c17cf769.wav -c:v qtrle -r 24 -crf 22 -map 0:v -map 1:a out.mov -y
- Resize transparent video
ffmpeg -i test.mov -vf "scale=640:-1:flags=lanczos" -c:v qtrle oput2.mov
I have tried a method from another guy and solved this problem, link here "https://github.com/Zulko/moviepy/issues/1555", according to his code, I just add a tag as "has_mask=True" in my code when using the func 'VideoFileClip()', then it works, that's amazing, but it's not bad.