Yet another tech blog

Tags Denial-of-playback

· Read in about 3 min · (584 Words)
android id3 flac

In the past years I’ve encountered some FLAC files that for some reason refused to play on my Android devices. When I did try to play them, I was greeted by the following message:

Sorry, the player does not support this type of audio file. Error Message

Until recently I’ve accepted this to be a bug in Android / my music player app (PlayerPro which is awesome!). But I’ve decided to try and uncover what made those FLAC files “unsupported”, which turned out to be easier than I initially thought.

ID3 and FLAC, Will it blend?

So the first thing I’ve tried is running file against a known “good” FLAC file and a “bad” one, which gave me the following output:

$ file good.flac
good.flac: FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 5688312 samples

$ file bad.flac
bad.flac: Audio file with ID3 version 2.3.0, unsynchronized frames, contains:FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 5944092 samples

What caught my eyes here was the mentioning of ID3 in the bad sample file.

From Wikipedia:

ID3 is a metadata container most often used in conjunction with the MP3 audio file format. It allows information such as the title, artist, album, track number, and other information about the file to be stored in the file itself.

For no clear reason I tried running flac against the bad sample file:

$ flac bad.flac

flac 1.3.2
Copyright (C) 2000-2009  Josh Coalson, 2011-2016  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac` for details.

ERROR: input file bad.flac has an ID3v2 tag

From there it was clear to me that my FLAC files shouldn’t contain ID3 tags.

But why?

After a little bit of searching I’ve found following explanation inside the FLAC FAQ:

FLAC has it’s own native tagging system which is identical to that of Vorbis. They are called alternately “FLAC tags” and “Vorbis comments”. It is the only tagging system required and guaranteed to be supported by FLAC implementations.

Out of convenience, the reference decoder knows how to skip ID3 tags so that they don’t interfere with decoding. But you should not expect any tags beside FLAC tags to be supported in applications; some implementations may not even be able to decode a FLAC file with ID3 tags.

So basically, this means some FLAC decoders might not support FLAC files that are wrapped by ID3.

Cleanup Time

So for us to fix this, all that we need to do is to remove the ID3 tags from our FLAC files.
While there are probably many ways and tools to achieve this, I’ve chose id3v2, which is a command line editor for id3v2 (shocking, I know!) tags.

Lets see what we get after running this tool:

$ file bad.flac
bad.flac: Audio file with ID3 version 2.3.0, unsynchronized frames, contains:FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 5944092 samples

$ id3v2 --delete-all bad.flac
Stripping id3 tag in "bad.flac"...id3v1 and v2 stripped.

$ file bad.flac
bad.flac: FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 5944092 samples

As expected, our bad sample now looks like a proper FLAC file!

Of course we don’t want to do this manually for every file, so to remove ID3 from all of the FLAC files in our music library we can use the following command:

cd /path/to/my/music/library
find . -name "*.flac" -exec id3v2 --delete-all {};

When testing the files again on my Android phone, they played without any issues.

Comments