1

I wanted to make a code that converts video into audio by a button in python and that is my code:

from tkinter import *
from tkinter.filedialog import askdirectory
from tkinter.filedialog import askopenfile
from moviepy.editor import *

def def_button():
    global Mp4
    global Mp4_Data
    Mp4 = askopenfile()
    if str(Mp4.name)[-4:] != ".mp4":
        Mp4_Data = Label(root, text="That's NOT a Mp4 Video", font="decorative 9 bold", fg="red").grid(row=9, column=0,
                                                                                                       columnspan=3)
    else:
        inactive_buttons() #function to make the button inactive to avoid double clicks
        mp4_frames = AudioFileClip(Mp4.name)
        audio = str(Mp4.name).replace(".mp4", ".mp3")
        mp4_frames.write_audiofile(audio)
        Mp4_Data = Label(root, text="The Audio Is being Uploaded into Video's Path", font="decorative 9 bold", fg="red") #feed back for the user
        Mp4_Data.grid(row=9, column=0, columnspan=3)
        assert isinstance(mp4_frames, object)
        mp4_frames.close()
        active_buttons() #function to make the button active after downloading

button = Button(root, text="Convert a Video into Audio", font="decorative 9 bold", width=50, fg="white", bg="#EF0000",
                  command=def_button)
button.grid(row=10, column=0, columnspan=3)
Mp4_Data = Label(root, text=" ").grid(row=9, column=0, columnspan=3)

but somehow there is a big error output:

File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\io\readers.py", line 193, in get_frame
    result[in_time] = self.buffer[indices]
IndexError: index -100001 is out of bounds for axis 0 with size 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\YT_Video_Downloader.py", line 115, in def_button6
    mp4_frames.write_audiofile(Mp4.name+".mp3")
  File "<decorator-gen-45>", line 2, in write_audiofile
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\AudioClip.py", line 206, in write_audiofile
    return ffmpeg_audiowrite(self, filename, fps, nbytes, buffersize,
  File "<decorator-gen-9>", line 2, in ffmpeg_audiowrite
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 166, in ffmpeg_audiowrite
    for chunk in clip.iter_chunks(chunksize=buffersize,
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\AudioClip.py", line 85, in iter_chunks
    yield self.to_soundarray(tt, nbytes=nbytes, quantize=quantize,
  File "<decorator-gen-44>", line 2, in to_soundarray
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\AudioClip.py", line 127, in to_soundarray
    snd_array = self.get_frame(tt)
  File "<decorator-gen-11>", line 2, in get_frame
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 77, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "C:\Users\Stem Asyut\PycharmProjects\pythonProject\venv\lib\site-packages\moviepy\audio\io\readers.py", line 205, in get_frame
    result[in_time] = self.buffer[indices]
IndexError: index -100001 is out of bounds for axis 0 with size 0

and I don't know why that's happening. I tried a lot of things and I have the same problem.

SO is there anyone who could help me with that problem because I didn't find anything about that on the internet?

Richard Wilson
  • 297
  • 4
  • 17

0 Answers0