Home > Enterprise >  MoviePy Audio doesn't exist on iPhone
MoviePy Audio doesn't exist on iPhone

Time:07-17

I have produced a video using MoviePy and the audio works perfectly fine on PC, but when I try watch it on iPhone it has no audio. I played the uploaded clip on my PC too so it's not the platform where the video is. Also got a friend to listen on iPhone and it also has no audio so not my device. Edit: also tried playing on samsung tablet (android) and it also plays the audio fine.

This is the outputted video files properties:

enter image description here

This is my code:

from moviepy.editor import ImageClip, AudioFileClip, VideoFileClip, CompositeVideoClip

    clips = []  # list of clips to be composited
    current_duration = 0  # how long the total clip is
    
    bg = VideoFileClip("background.MOV", audio=False)  # remove audio from the background
    
    title_audio = AudioFileClip("audio/title.mp3")  # title audio
    title_clip = ImageClip("screenshots/post.png", duration=title_audio.duration).set_audio(title_audio)  # image   audio
    clips.append(title_clip.resize(width=bg.w).set_position("center"))  # append the resized centred clip
    current_duration  = title_audio.duration  # increase the duration
    
    # loop through clips 1-5 doing the same thing
    for comment in range(1, 6):
        com_audio = AudioFileClip("audio/voice"   str(comment)   ".mp3")
        com_clip = ImageClip("screenshots/comment"   str(comment)   ".png", duration=com_audio.duration).set_audio(com_audio)
        clips.append(com_clip.set_start(current_duration).resize(width=bg.w).set_position("center"))  # start at current end
        current_duration  = com_audio.duration
    
    final = CompositeVideoClip([bg.subclip(0, current_duration)]   clips)  # composite the clips on top of the background
    final.write_videofile("test.mp4", fps=24)  # output the file

CodePudding user response:

Based on this, you produced a video file that's (probably) h264/mp3, which isn't a supported format for iPhone - your video file needs to be h264/aac to work on iPhones (and probably any Mac device via Quicktime).

This is also an open issue for moviepy: https://github.com/Zulko/moviepy/issues/1709

You can specify an audio_codec when writing your file to make this work:

final.write_videofile("test.mp4", fps=24, audio_codec='aac')  # output the file
  • Related