1

Im trying to write a program that creates an mp4 from a static image and an audio file.

Here is the code im using so far:

from moviepy.editor import AudioFileClip, ImageClip

def mp3PNGMerge(fileSaveName):
    
    audio_clip = AudioFileClip("[PATH TO AUDIO]")
    image_clip = ImageClip("PATH TO IMAGE")
    video_clip = image_clip.set_audio(audio_clip)
    video_clip.duration = audio_clip.duration
    video_clip.fps = 1
    video_clip.write_videofile(fileSaveName + '_CLIP.mp4')

mp3PNGMerge('[OUTPUT FILE NAME]')

However when this is run, the program creates a video the length of the audio clip but does not play the audio, it is completely silent.

Does anyone know what is going on here?

invisabuble
  • 149
  • 1
  • 3
  • 12

2 Answers2

0

The logic should be to set your sound on videoClip not imageClip.

I don't use MoviePY or Python but from looking at the docs, I would try as:

from moviepy.editor import AudioFileClip, ImageClip

def mp3PNGMerge(fileSaveName):
    
    audio_clip = AudioFileClip("[PATH TO AUDIO]")
    image_clip = ImageClip("PATH TO IMAGE")
    
    video_clip = VideoClip(image_clip)
    video_clip.set_audio(audio_clip)
    video_clip.duration = audio_clip.duration
    
    video_clip.fps = 30
    video_clip.write_videofile(fileSaveName + '_CLIP.mp4')

mp3PNGMerge('[OUTPUT FILE NAME]')

I don't know if it will get you on the right track (eg: maybe video_clip.set_audio( ... ) is supposed to be set as video_clip.audio( ... ). The code logic should be correct.

Let me know how it goes (eg: I can delete this post if it's not a correct Answer).

VC.One
  • 14,790
  • 4
  • 25
  • 57
0

change the video_clip.fps to 30, audio file can't be played on 1 fps

from moviepy.editor import AudioFileClip, ImageClip

def mp3PNGMerge(fileSaveName):

audio_clip = AudioFileClip("[PATH TO AUDIO]")
image_clip = ImageClip("PATH TO IMAGE")
video_clip = image_clip.set_audio(audio_clip)
video_clip.duration = audio_clip.duration
video_clip.fps = 30
video_clip.write_videofile(fileSaveName + '_CLIP.mp4')

mp3PNGMerge('[OUTPUT FILE NAME]')
imzigler
  • 1
  • 1