fre:ac Creating malformed image/jpg mp3 tag when ripping flac to mp3?
When converting a flac file that contains an image tag to an mp3 using the LAME encoder, the resulting mp3 file does contain the image tag, but when viewed in the mp3tag editor the image type is missing. I.E. when looking at the image/cover tag you normally see 4 lines, for example:
image/jpeg 600x600 124 KB Front Cover
However, in the cases this issue occurs you only see:
600x600 124 KB Front Cover
This results in iTunes in Windows not recognizing the image tag. I am not sure if it negatively effects any other mp3 players.
Steps to reproduce the behavior:
- Convert a .flac file that contains an image tag to .mp3 using the LAME encoder.
Context It is possible that the tag is somehow messed up on the flac file. I have only had this happen from downloaded flacs that I am converting to mp3s. When I rip a flac from a PC and then create an mp3 I generally don't attach the cover to the flac until after it has been converted to mp3.
The solution has been to remove the image tag from the mp3, save, and then re-add it with mp3tag, at which point everything seems to look and work normally.
OS: Windows 10
In the attached images you can seen the distinction. In the first image, the mp3 file was edited and the image was added manually. Note the image type shown on the first line under the image as "image/jpeg". On the next photo the image was added (copied?) to the mp3 file via fre:ac v1.1.7 during the rip from a flac file, which contained the image. There you can see the image type is missing where the red circle is. MP3TAG handles the tag fine as you can see the image in both cases, however in the third photo, there is something about the tag missing that info that iTunes does not like, such that when it is imported into iTunes the cover won't display. However, if I remove the cover with mp3tag, save the mp3, then manually add it back and save, that fixes the file and upon refreshing the file in iTunes the cover will then show up.
My assumption therefore is that the way that fre:ac writes the image tag to the file is different and/or incomplete vs. how mp3tag writes the image tag.
Could you post the FLAC file that didn't convert? You could chop it down to just a few seconds with Audacity or something (as long as it still causes the error). Converting flac to mp3 with an embedded image worked for me. Process:
- Create a short audio clip (whitenoise) in Audacity 3.4.2 on Linux Mint 22.0 and export as flac.
- Create 600x600 jpg image in GIMP 2.10.36 on Linux Mint 22.0
- Use metaflac 1.4.3 on Linux Mint 22.0 reference implementation to embed the image into the flac file
metaflac --import-picture-from="SampleImage.jpg" whitenoise.flac - Use Fre:ac 1.1.7 (Linux Mint 22.0 built from source) to convert with the LAME MP3 Encoder v3.100 on standard presets
- Verify Mp3tag v3.31a 64 bit on Windows 10 shows "image/jpeg" and displays picture
- Verify iTunes 12.13.7.1 64 bit on Windows 10 shows the artwork.
I made two conversions from a flac, one converted with the image from flac to mp3 with the lame encoder, one also converted and with the same art embedded using mp3tag
I compared these more closely and I found more details, the red highlighted portion shows what's going wrong, it's writing correctly but it's also writing a field before with the image/jpeg tag missing, and most players only look at the first image tag and ignore the rest
Additionally i compared the hex data on the same song and found differences
Correct
Incorrect
Note on the start of the id3 header on the correct implementation it's "vTALB" while on the broken one it's "{TALB" and additionally on the broken one the "...image/jpeg... text is missing completely
EDIT: Now it is only embedding the empty APIC frame, not the empty and then the normal, i have changed no settings and am using the same files
Some addtional detail
- This happens on both linux and windows
- This bug does not apply to any of the other encoders
- I used LAME 3.100 directly with ffmpeg and this bug did not occur
- Size of image is not a factor
- Type of image is not a factor (png vs jpeg)
- Converting from flac or WAV produces the same result (broken embed)
Successfully replicated this tonight on win10 on version 1.1.7
- Pick a FLAC to convert to mp3, with default settings ('standard', 'lame mp3 encoder 3.100'—see picrelated)
- Open mp3 in VLC (I have 3.0.20); mp3 displays image.
- Open both files in mp3tag for comparison—see that the FLAC shows
image/jpegabove other metadata about cover art, but that it is missing in the data for the mp3's cover art: - Using plain ffmpeg, convert the FLAC to mp3, and perform the same inspection, finding that the missing info IS embedded in the mp3 (edit: I had to add
-map 0:a -map 0:v -c:v copyto the ffmpeg command, so that it wouldn't automatically convert the jpeg to a png)
Also included the log from ffmpeg in the event there might be some useful information there ffmpeg.log
I investigated this issue with the help of Codex. I am not a programmer, so I cannot independently review the code, but I tested a modified fre:ac 1.1.7 build with a FLAC that previously produced an MP3 cover image with an empty MIME type. After the change below, the MP3 cover reports image/jpeg and is recognized correctly.
Codex found that the FLAC picture already had a MIME type. The value was lost when BoCA wrote the ID3v2 APIC frame. It identified this line in components/tagger/id3v2/id3v2.cpp and changed how the MIME field is written:
- if (picInfo.mime != NIL) SetStringField(frame_picture, ID3FN_MIMETYPE, picInfo.mime.ConvertTo("ISO-8859-1"));
+ if (picInfo.mime != NIL) frame_picture.GetField(ID3FN_MIMETYPE)->Set((char *) picInfo.mime.ConvertTo("ISO-8859-1"));
Codex's explanation is that the APIC MIME field is a non-encoded C string, while SetStringField uses the frame's text encoding. The modified build fixed the problem in my test. I hope this gives you a useful starting point for checking and fixing the issue upstream.
I do not know how to program; testing the modified application and sharing this finding is the most help I can offer.