Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Oct 29, 2024 · 1 comment
Labels
bug Issues that report (apparent) bugs.

Comments

@JoelOnyedika
Copy link

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

  • MoviePy Version: (Include your MoviePy version)
  • Python Version: (Include your Python version)
  • Operating System: (Include your OS)
  • FFmpeg Version: (If available, provide FFmpeg version)
  • Audio File Location: (Specify if the audio file path is absolute or relative)

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

  • Verified that the audio file (audio.mp3) exists in the specified path.
  • Ensured that FFmpeg is correctly configured and accessible.
  • Attempted to read other audio files to see if the issue persists.
  • (Include any other troubleshooting steps you took)

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!.

@JoelOnyedika JoelOnyedika added the bug Issues that report (apparent) bugs. label Oct 29, 2024
@steinathan
Copy link

whats the result of ffprobe?

ffprobe -i audio.mp3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

2 participants