Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouldntDecodeError: Decoding failed. ffmpeg returned error code: 69

While trying to use audiosegment.from_file(x.mp3) to open an mp3 file and later convert it to wave format by audio.export(x.mp3, format='wav'), I face the following Couldnt DecodeError.

What could be causing this? I am using python= 3.9, pydub=0.25.1, audiosegment=0.23.0.

Thanks in advance for the help. Below is the error shown on the console.

CouldntDecodeError                        Traceback (most recent call last)
/var/folders/vh/nmgr0zd56yd_vs_56q_jy89c0000gn/T/ipykernel_21698/1373432166.py in <module>
      1 vad=wb.Vad()
      2 filename= '/Users/gulag_dweller/Desktop/Lab_stuff/python_script/Isi_B1.mp3'
----> 3 audio= audiosegment.from_file(filename)
      4 audio_wav= audio.export(filename, format ='wav')
      5 

~/mambaforge/lib/python3.9/site-packages/audiosegment.py in from_file(path)
   1131     _name, ext = os.path.splitext(path)
   1132     ext = ext.lower()[1:]
-> 1133     seg = pydub.AudioSegment.from_file(path, ext)
   1134     return AudioSegment(seg, path)
   1135 

~/mambaforge/lib/python3.9/site-packages/pydub/audio_segment.py in from_file(cls, file, format, codec, parameters, start_second, duration, **kwargs)
    771             if close_file:
    772                 file.close()
--> 773             raise CouldntDecodeError(
    774                 "Decoding failed. ffmpeg returned error code: {0}\n\nOutput from ffmpeg/avlib:\n\n{1}".format(
    775                     p.returncode, p_err.decode(errors='ignore') ))

CouldntDecodeError: Decoding failed. ffmpeg returned error code: 69

Output from ffmpeg/avlib:

ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with clang version 11.1.0 

1 Answers

I had the same problem. I read that there is some cases where mp3 files contain AAC audio, but the container format is mpeg4.

So, the solution that worked for me is:

try:
    audio = audiosegment.from_file(filename, "mp3")
except:
    audio = audiosegment.from_file(filename, format="mp4")
like image 63
lscena Avatar answered Aug 13 '26 05:08

lscena