1. Context

Recently, I was doing something that felt anachronistic: ripping a CD I own to be able to listen to it on my phone.

Why not listen to it on a streaming platform or buy the digital version of those songs? I can’t, since it was never released outside a physical CD, and no streaming platform offers it anywhere.

2. Simple, almost

After finding a USB CD drive, I ripped it and entered names manually using Sound Juicer, and ripped it to flac files.

I want to listen to them with Apple Music, which does not read flac by default, so I conjure a small script using ffmpeg to convert my flacs to alac files:

ffmpeg -y -i song.flac -c:v copy -acodec alac song.m4a

This says:

  • -y: override output files without asking

  • -i: input file

  • -c:v copy: copy any video as-is (in this case, the album cover)

  • -acodec alac: convert to lossless alac format

3. Problem

I first try the files through mpv and mpd on linux, and everything plays as expected.

I import them into Apple Music on my laptop without any issues, and then synchronise them on my phone.

Days later, I listen to the first song of the album on my phone, and it plays fine, except it seems to take 30 minutes to switch to the second song. Same from the second to the third song.

I check my phone, and each song seems to last 38 minutes, yet the album duration is shown as 38 minutes.

I’m starting to wonder if the original flac files didn’t have an incorrect length.

4. Back on the laptop

Yet, on Apple Music on MacOS, the files last for their exact length and they play the next song without delay.

I open the files in Audacity to check the waveform: all seems well too. mpv and mdp show no issues as well.

I’m starting to think it might be some sort of issues with Apple Music on iOS.

Searching online for songs playing longer than their length do not return anything useful.

I’m out of ideas, and leave it at that.

5. iTunes

One day, I remember that QuickTime player is available on MacOS, and I wonder if it would work in it: surprise, it has the same issue as Apple Music on iOS and it plays for too long!

Now I’m starting to think there must be something weird with the audio files. I wander in the QuickTime player menu to see if I can see something funny, and I notice that I can click on View −> Next Chapter.

But this is not a film, and there should not be any chapters in there!

6. The problem

It does seem that Sound Juicer added some chapters information in the metadata of the flac files at first, 1 for each song in the album.

Then, ffmpeg did copy that information to the m4a files.

At this point, each music player handled that information differently:

  • mpv, mpd, Apple Music on MacOS: played the file and stopped when the data is finished and disregard chapters set in the future;

  • QuickTime Player and Apple Music on iOS: played the file, but padded the file with silence so that it continues playing until the last chapter.

7. A Solution

I was unable to found out why Sound Juicer includes chapters in the audio file, or why ffmpeg does not complain of chapters set outside the stream of data, or why Apple Music handles that info differently depending on the platform.

What I can do is ask ffmpeg to actually drop the chapters when converting from flac to alac with -map_chapters -1:

ffmpeg -y -i song.flac -c:v copy -acodec alac  -map_chapters -1 song.m4a