Open File with JSONDecodeError
See original GitHub issueExpected 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
- Python version: 3.7.4
- Pydub version: 0.23.1
- ffmpeg or avlib?: ffmpeg
- ffmpeg/avlib version: 1.4
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
Python json decode error when opening a basic json file
I'm pretty sure that your test1.json file contains a byte order mark. Use the encoding parameter for open() function.
Read more >Python JSONDecodeError Explanation and Solution | CK
First, we import the json module which we use to read a JSON file. Then, we use an open() statement to read the...
Read more >json.decoder.JSONDecodeError: Extra data in Python
The Python json.decoder.JSONDecodeError: Extra data occurs when we try to parse multiple objects without wrapping them in an array.
Read more >json — JSON encoder and decoder — Python 3.11.1 ...
JSONDecodeError will be raised if the given JSON document is not valid. ... The RFC prohibits adding a byte order mark (BOM) to...
Read more >Python JSON tricks: how to deal with JSONDecodeError
You should be careful when you read the JSON from some file or manually write ... for keys and values, otherwise you will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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!