Zulko / moviepy

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

Disappearing transparent pixels when using .resize() feature #1881

Open EliTheDev opened 1 year ago

EliTheDev commented 1 year ago

Below is simplified code for a script I'm programming to overlay PNG files with subtitles over a video:

import moviepy.editor as moviepy
from moviepy import *

input_vid = moviepy.VideoFileClip("input.mp4").set_duration(10)
input_width = moviepy.VideoFileClip("input.mp4").w
input_height = moviepy.VideoFileClip("input.mp4").h

clips = [input_vid];
img = moviepy.ImageClip('./subtitles/1.png')
clips.append(   img.set_start(0).set_duration(5).set_pos(lambda t: (    input_width / 2 - img.w*(1+t/5)/ 2, input_height / 2 - img.h*(1+t/5)/2  )).resize(lambda t: 1+t/5)     )   #  #.set_pos(((input_width / 2) - (img_w / 2), (input_height / 2) - (img_h/2)))   )

print('Compositing...')
video = moviepy.CompositeVideoClip(clips).set_duration(10)
print('Done.')
print('Exporting...')
video.write_videofile("moviepy_test.mp4",codec='libx264')

-->

Expected Behavior

The photo contains a transparent shadow generated with PIL. It's imported as a PNG. 1

It should overlay over the video like so and slowly grow in size: 3

Actual Behavior

Instead, the overlay does increase is size however the transparent pixels disappear: 2

Steps to Reproduce the Problem

  1. Import video and photo with transparent pixels
  2. Increase the photo over time with lambda and .resize()
  3. Composite the two together
  4. Export the result
import moviepy.editor as moviepy

#import base video and image with transparent pixels
input_vid = moviepy.VideoFileClip("input.mp4").set_duration(5)
opaque_img = moviepy.ImageClip('./subtitles/1.png').set_duration(3)

#overlay the two together and resize the overlay with lambda animation
output_vid = moviepy.CompositeVideoClip([ input_vid, opaque_img.resize(lambda t: 1+t).set_position(('center', 'center')) ])

#export
output_vid.write_videofile("output.mp4",codec='libx264')

Specifications

hajdaini commented 1 year ago

We still have the same problem in last version of moviepy ...

LiuXiaolong19920720 commented 8 months ago

Same problem, any progress?

fjsnow commented 8 months ago

Same here. Any workaround?