0

I am attempting to add an image behind a video using moviepy and cannot come up with any way to do it. My image dimension is (1080 x 720) and my video dimension is (200 x 200). I am trying to put the video file on top of the image file, place it in the midlle and export the final video with the dimensions of the image. This is a visual representation of what I am trying to achieve:

View image

I tried doing this with the following code, but could not manage to get it to work. Any help is seriously appreciated :)

import moviepy
import moviepy.editor as mp

video = mp.VideoFileClip("/media/pi/vid.mp4")

logo = (mp.ImageClip("/media/pi/pic.png"))

# Preferably I would want the image to be the same duration as the video file. 
# The following was just for testing.
final = mp.CompositeVideoClip([video, logo.set_duration(3)])
final.write_videofile("test.mp4")
George Lua
  • 17
  • 1
  • 5

1 Answers1

1

Hello!

I can't test it now, but here it said that

Note that by default the composition has the size of its first clip (as it is generally a background)

So maybe you should try this (if you don't know, what is "center", you should see docs):

import moviepy
import moviepy.editor as mp

video = mp.VideoFileClip("/media/pi/vid.mp4")
logo = (mp.ImageClip("/media/pi/pic.png"))

final = mp.CompositeVideoClip([logo, video.set_position("center")])
final.write_videofile("test.mp4")

SIDE NOTE: you should downgrade from moviepy 1.0.1 to moviepy 1.0.0, otherwise you will get an "object has no attribute stdout" error or something like that. To downgrade:

pip install moviepy==1.0.0 

or

 pip3 install moviepy = 1.0.0
Community
  • 1
  • 1
diduk001
  • 202
  • 1
  • 11