jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.94k stars 1.05k forks source link

Open File with JSONDecodeError #450

Open liangmx17 opened 4 years ago

liangmx17 commented 4 years ago

Expected behavior

open a mp3 with no error

Actual behavior

I used the script below:

from pydub import AudioSegment
song = AudioSegment.from_mp3(r"test2.mp3")

and there is a JSONDecodeError

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

more detail:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-10-87da299a1c3c> in <module>
      1 from pydub import AudioSegment
      2 
----> 3 song = AudioSegment.from_mp3(r"test2.mp3")
      4 

C:\ProgramData\Anaconda3\lib\site-packages\pydub\audio_segment.py in from_mp3(cls, file, parameters)
    714     @classmethod
    715     def from_mp3(cls, file, parameters=None):
--> 716         return cls.from_file(file, 'mp3', parameters=parameters)
    717 
    718     @classmethod

C:\ProgramData\Anaconda3\lib\site-packages\pydub\audio_segment.py in from_file(cls, file, format, codec, parameters, **kwargs)
    663             stdin_data = file.read()
    664 
--> 665         info = mediainfo_json(orig_file)
    666         if info:
    667             audio_streams = [x for x in info['streams']

C:\ProgramData\Anaconda3\lib\site-packages\pydub\utils.py in mediainfo_json(filepath)
    266     stderr = stderr.decode("utf-8", 'ignore')
    267 
--> 268     info = json.loads(output)
    269 
    270     if not info:

C:\ProgramData\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    346             parse_int is None and parse_float is None and
    347             parse_constant is None and object_pairs_hook is None and not kw):
--> 348         return _default_decoder.decode(s)
    349     if cls is None:
    350         cls = JSONDecoder

C:\ProgramData\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
    335 
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

C:\ProgramData\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

Your System configuration

lloxis commented 4 years ago

How to fix this ?

alvst commented 4 years ago

I was experiencing this problem but was able to fix it by deleting and reinstalling ffmpeg. There is an older issue that was solved where this was the fix. It is caused by having a customize output location for ffmpeg which Pydub does not expect.

ericman93 commented 4 years ago

try to run ffmpeg in terminal mine issue was

dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib 

Running brew doctor I saw that fontconfig wasn't linked, after linking it everything was working

Koruption commented 4 years ago

Has there been a dedicated fix for this or is it an external error? I've followed the recommendations and the issues persists. I'm running ffmpeg v4.2 and can confirm that running ffmpeg in the terminal provides the expected results.

kylefoley76 commented 4 years ago

I also am having a lot of problems with this. I'm not able to run FFmpeg in the terminal on a mac because I can't find it. I have downloaded it with brew, but after that I don't know where it goes. When I look for it with the spotlight all I get is some ffmpeg in python folders. I have also tried brew doctor and then linking some things but that did not work.

kylefoley76 commented 4 years ago

I got it working. In short, it is an ffmpeg problem not a pydub problem. I had to reinstall ffmpeg not once but twice and it took a lot of work to get it to work and I've forgotten how I did it. In any case, if you can get this line in Terminal to work ffmpeg -i input.mp3 output.avi then pydub should work.

khalilchatoo commented 3 years ago

@kylefoley76 do you by chance happen to have the flags you used when you compiled FFmpeg handy? running into this issue right now

tuotuoZ commented 3 years ago

I installed ffmpeg with conda and problem solved. Try this conda install -c conda-forge ffmpeg

joekadi commented 3 years ago

Solved for MacOS using Anaconda3 by downloading ffmpeg and and ffprobe binaries from https://ffbinaries.com/downloads and putting them in my "usr/anaconda3/bin" folder (this directory primarily has executable files). I think the issue occurred because even though I had uninstalled and reinstalled pydub and ffmpeg several times, it was still running an old version of the executables that I had installed from a year ago!

JohnYeung-dojjy commented 2 years ago

problem solved in windows 10 py3.8 by reinstalling ffmpeg using

conda install -c conda-forge ffmpeg

freemedom commented 3 weeks ago

this is probably because chinese windows system use gbk code instead of utf-8

freemedom commented 3 weeks ago

it can't get the output from Popen that is gbk encoded

freemedom commented 3 weeks ago

besides, in windows, path seems is not work. https://stackoverflow.com/questions/5658622/python-subprocess-popen-environment-path it needs to restart the pycharm.