0

I been trying this for a long time, but doesn't seem to work, I have tried using multiple codes, this is one of them that i'm currently using but doesn't seem to work:

from moviepy.editor import *

image = ImageClip("image.jpg")

audio = AudioFileClip("audio.mp3")

video = CompositeVideoClip([image.set_duration(audio.duration)])
video = video.set_audio(audio)

video.write_videofile("output.mp4", fps=24)

1 Answers1

1

Try This way it should give u the desired result:

from moviepy.editor import *
# Import the audio(Insert to location of your audio instead of audioClip.mp3)
audio = AudioFileClip("audio.mp3")
# Import the Image and set its duration same as the audio (Insert the location 
of your photo instead of photo.jpg)
clip = ImageClip("image.jpg").set_duration(audio.duration)
# Set the audio of the clip
clip = clip.set_audio(audio)
# Export the clip
clip.write_videofile("video.mp4", fps=24)
  • thanks, unfortunately this wan't the issue, my code runs perfectly now, I just needed to uninstall and reinstall moviepy – AcAudi McErcedes Feb 11 '23 at 10:55
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 15 '23 at 07:18