quodlibet / mutagen

Python module for handling audio metadata

Home Page:https://mutagen.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't open wav ripped from DVD audio: Invalid Chunk - ordinal not in range(128)

Tailslide opened this issue · comments

Created some wav files with DVD Audio Extractor 8.4.2 from a DTS source... they work on fb2k allright.

When I open with

file = mutagen.wave.WAVE(localfile)

I get:

InvalidChunk(UnicodeDecodeError('ascii', b'\x7f\xfe\x80\x01', 1, 2, 'ordinal not in range(128)'))
Stack Trace
Traceback (most recent call last):
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_iff.py", line 106, in parse
    id = id.decode('ascii').rstrip()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 1: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\source\plexmusic-rating-sync\sync-plex-music-ratings.py", line 218, in <module>
    file = getFile(localfile)
  File "c:\source\plexmusic-rating-sync\sync-plex-music-ratings.py", line 72, in getFile
    file = mutagen.wave.WAVE(localfile)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_file.py", line 47, in __init__
    self.load(*args, **kwargs)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_util.py", line 184, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_util.py", line 155, in wrapper
    return func(self, h, *args, **kwargs)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\wave.py", line 196, in load
    self.info = WaveStreamInfo(fileobj)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_util.py", line 184, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\wave.py", line 75, in __init__
    wave_file = _WaveFile(fileobj)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\wave.py", line 38, in __init__
    RiffFile.__init__(self, fileobj)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_riff.py", line 63, in __init__
    super().__init__(RiffChunk, fileobj)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_iff.py", line 317, in __init__
    self.root = chunk_cls.parse(fileobj)
  File "C:\Users\gregp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mutagen\_iff.py", line 108, in parse
    raise InvalidChunk(e)
mutagen._iff.InvalidChunk: 'ascii' codec can't decode byte 0xfe in position 1: ordinal not in range(128)

From the given info it's not possible to see what the issue is. Can you share an affected file and the full stack trace?

I added the stack trace above.
The file is copyrighted is there some way I can send it to you direct or is a hex dump of the first bit sufficient?

I think what's going on is I have some dts files inside a wav container and some that are not inside a wav container that I misnamed from .dts to .wav. Looks like foobar supports addings tags to .dts files but I'm not sure if it's supported or how I would open these in mutagen.

If those are not actually WAVE files than this would of course explain a lot :) The stack trace also shows that parsing the file fails already at the very beginning, so it's definitely not a WAVE file.

mutagen has currently no support for reading .dts files. I am not super familiar with .dts files, but AFAIK those are basically just bare DTS audio streams with some very basic file structure that in itself does not allow metadata (similar to how .aac files are for AAC audio). The discussion at https://forum.videohelp.com/threads/381761-Container-for-DTS-audio indicates that foobar2000 supports tucking APE tags at the end of the .dts file for metadata support, but this could cause compatibility issues with other software (again similar to .aac).

For best compatibility you would better wrap the DTS audio into a proper container format. Matroska (as a .mka file in this case) would be frequently recommended here, but as mutagen does not yet support Matroska it probably does not bring you any further. I think it should also be possible to use a MP4 container instead. In regards to tagging that would probably offer the best compatibility. No idea about playback compatibility, though.

I got myself a .dts file. It's really just the bare DTS encoded audio, without anything extra or any supporting file structure. So there is not really much tagging to be done here. It is in general possible to put an APE tag at the end, as foobar2000 does, but playback software not supporting this would just attempt to interpret this as audio data and fail in unexpected ways. A typical issue with this kind of tagging is that software reports a longer playback duration as it uses the byte size of the audio to estimate the duration.

I would actually try to put those files into a MP4 container and see whether your playback software can handle it. You can do this with ffmpeg with something like ffmpeg -i source.dts -c:a copy output.mp4.

Or use .mka as the output, but mutagen won't be able to tag them in this case.

Everything you say matches up with what I see playing around with the files. I wound up converting them all to multichannel FLAC since this seems the best compromise despite triggering my programmer OCD by being a one way conversion to a larger file. The files in .wav containers would only play in stereo on some players and when I converted the .dts files to FLAC it complained about corruption at the end presumably from whatever meta that foobar is attaching to the end. I heard some horror stories about trying to stream multichannel FLAC to receivers but this seems like the least bad option.

Thanks for taking a look at this.. I’ll close this (non) issue.