I am trying to create a simple video of one image with audio with MoviePy. Working with the same code, sometimes MoviePy randomly produces greyed out and glitched videos like this: (opened with VLC Media Player)
The audio works fine in the final video, and the image used is also completely fine.
I tried searching but couldn't find anything that worked. I also re-downloaded FFMPEG
, thinking it would solve the problem, but to no advantage.
The code I am using is:
# assume aud_path, vid_path and out_path are set and imports have been done
aud_clip = AudioFileClip(aud_path)
vid_clip = ImageClip(vid_path)
vid_clip = vid_clip.set_audio(aud_clip).set_duration(aud_clip.duration)
vid_clip.write_videofile(out_path, temp_audiofile='temp-audio.m4a', remove_temp=True, codec="libx264", audio_codec="aac", fps=24)
Any help will be appreciated.
I figured it out! For anyone having a similar problem, the problem was in the vid_clip.write_videfile()
method in the codec
argument.
I changed the codec
to "mpeg4"
and it is working fine now.