Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.54k stars 1.57k forks source link

The class AudioFileClip not able to read audio and returns an Index error out of range error, when using the latest ffmpeg binary #2233

Open JoelOnyedika opened 1 week ago

JoelOnyedika commented 1 week ago

Here’s a template for a GitHub issue you can use to report the problem you’re facing with MoviePy when trying to read an audio file. You can fill in any additional details as needed.


Title: Error When Reading Audio File with MoviePy: IndexError. I would love a reply ASAP

Description

I'm encountering an issue when using MoviePy to read an audio file. Specifically, I receive an IndexError when trying to create an AudioFileClip when using the latest version of FFMPEG. It seems that the FFMPEG_AudioReader is failing to parse the audio file, leading to an empty list being returned, which subsequently causes the error.

Steps to Reproduce

  1. Attempted to read an audio file using MoviePy in my Flask application:

    from moviepy.editor import AudioFileClip
    
    def generate_tiktok_video():
       audio_clip = AudioFileClip("audio.mp3")  # This line causes the error
  2. Received the following error trace:
    Traceback (most recent call last):
     ...
     audio_clip = AudioFileClip("audio.mp3")
    File "C:\Users\USER\Documents\Coding\sidehustles\Tweetflow\backend\env\Lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 70, in __init__
       self.reader = FFMPEG_AudioReader(filename, fps=fps, nbytes=nbytes,
    File "C:\Users\USER\Documents\Coding\sidehustles\Tweetflow\backend\env\Lib\site-packages\moviepy\audio\io\readers.py", line 51, in __init__
       infos = ffmpeg_parse_infos(filename)
    File "C:\Users\USER\Documents\Coding\sidehustles\Tweetflow\backend\env\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 269, in ffmpeg_parse_infos
       if "No such file or directory" in lines[-1]:
         IndexError: list index out of range

Expected Behavior

The AudioFileClip should successfully read the audio file and allow me to use it in my video generation process.

Actual Behavior

Instead of successfully loading the audio file, I encounter an IndexError, indicating that the parsing of the audio file has failed.

Additional Information

A piece of my actual code

IMAGEMAGICK_BINARY = r"C:\Program Files\ImageMagick-7.1.1-Q16-HDRI\magick.exe"
    FFMPEG_BINARY = r'C:\ffmpeg\bin\ffmpeg.exe'

    change_settings({
        "IMAGEMAGICK_BINARY": IMAGEMAGICK_BINARY, 
        'FFMPEG_BINARY': FFMPEG_BINARY
    })

    data = request.get_json()
    print(data)
    # TikTok screen resolution (9:16 ratio)
    screen_width = 1080
    screen_height = 1920
    max_duration = 60  # Maximum duration for both video and audio in seconds
    output_filename="output.mp4"

    print('shit')

    # Remove any previous video file with the same name
    if os.path.exists(output_filename):
        os.remove(output_filename)

    # Generate audio from text
    generate_audio(data['text'])
    print('generating audio')

    # Load the generated audio
    audio_clip = AudioFileClip("audio.mp3")

Attempts to Resolve

My Opinion

I have some concerns regarding the maintenance and reliability of MoviePy:

  1. Project Maintenance: The last commit on this repository was about five months ago. This raises concerns about whether the project is still actively maintained.

  2. Critical Usage: I am using MoviePy in a SaaS project that has critical functionality. I cannot afford for it to break unexpectedly.

  3. Error Encountered: I am experiencing a specific error when trying to read audio files using MoviePy. If anyone has encountered this issue before, I would appreciate guidance on how to resolve it.

  4. Community Support: Is there an active community supporting this project? I want to know if I can rely on getting help and updates in the future.

  5. Advice on Usage: Given the current situation, would you recommend that I continue using MoviePy, or should I consider alternatives?

Request

I would appreciate any guidance on how to resolve this issue. Thank you!.

steinathan commented 5 days ago

whats the result of ffprobe?

ffprobe -i audio.mp3