Search code examples
pythonffmpegmoviepy

Audio problems when resizing video - moviepy


I am resizing an mp4 video with this code (moviepy):

video_clip = VideoFileClip(url)
resized = video_clip.resize(width=720)
d = tempfile.mkdtemp()
video_path = os.path.join(d, 'output.mp4')
resized.write_videofile(video_path)

The resized clip's audio works when I play it on my pc, but not on an iPhone. (The original clip's audio does work on my iPhone.)

How can I fix this?

First image: Codec of resized video
Second image: Codec of original video

Codec of resized video Codec of original video


Solution

  • Here is how I got it working:

    resized.write_videofile(video_path, temp_audiofile='temp-audio.m4a', remove_temp=True, codec="libx264", audio_codec="aac")