You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No gapless playback and bad seeking for mka (matroska) file with cue sheet. #1397
I have an album as Dolby Atmos in an mka container. To give cmus the information about the timestamps of the individual songs I have a cue file right next to it.
The seeking to the timestamps of the cue sheet is always a bit off. When selecting a song I often start around 1 second inside the song. This also leads to an album not playing gapless between songs which can sound annoying.
I know that my cue sheet has the correct timestamps because when I convert the Dolby Atmos stream to a flac and use the same exact cue sheet, the seeking to timestamps is perfect and gapless playback therefore works flawlessly.
uname -a:
Linux my-pc 6.6.69-1-lts #1 SMP PREEMPT_DYNAMIC Thu, 02 Jan 2025 22:00:49 +0000 x86_64 GNU/Linux
cmus --version:
cmus v2.12.0
Copyright 2004-2006 Timo Hirvonen
Copyright 2008-2016 Various Authors
I tried to reproduce this with an Atmos .mka and it seemed fine, so it could be a problem tied to seeking in the specific mka file that was being used. It seems less likely to be related to the cue sheet if it worked when converted to flac.
I have this problem with each of my Atmos files (underlying codec is TrueHD). And I also have the same problem with an mka file that has DTS inside.
There's nothing I can do wrong with my cue files for gapless to stop working, right? Because you only ever specify the starting timestamp of a song, and never the end.
So I assume it's either ffmpeg or broken file problem.
Can a file be broken in such a way that a full playback (with mpv or vlc) works perfectly fine, but when trying to accurately seek via a cue file it fails?
OK, maybe you're onto something. Just running mkvmerge -o newfile.mka oldfile.mka improves the situation massively. Now the seeking is only a few milliseconds late which makes normal playback of a song pretty much OK, but the transition from one song to the next sounds still a bit stuttery. With the old file the transitions were unbearable (imagine skipping a second at the beginning of each song).
EDIT: According to ffprobe the old file has "time_base": "1/1000" while the new one has "time_base": "651/31250000"
You can also try ffplay to make sure: ffplay -ss 1.1 file.mka ^ play file.mka starting from 1.1 sec
The seek of ffplay with the old file is actually a bit too early (as opposed to the one by cmus and audacious which is a bit too late). With the new one it seems spot on (or at least as spot on as cmus now.)
time_base should be equal 1/sample_rate (1/48000 in your case). If you try running ffprobe on your flac file, you'll see correct time_base. That's probably why seeking works perfectly for flac. I don't know how to change time_base of .mka though
time_base should be equal 1/sample_rate (1/48000 in your case). If you try running ffprobe on your flac file, you'll see correct time_base. That's probably why seeking works perfectly for flac. I don't know how to change time_base of .mka though
Oh my god, you're right. If I put the flac stream into an mka container then mkvmerge also gives it a time_base of 651/31250000 and cmus is slightly inaccurate when seeking.
So now I need to find out why mkvmerge sets it to this value and how to change it. I'll update when I know more.
Suggestion: When going from track n to track n+1, and both tracks are in the same file, then cmus should not seek the start of track n+1, but instead continue playing the file.
changed the title [-]No gapless playback and bad seeking for mka file with Dolby Atmos and cue sheet.[/-][+]No gapless playback and bad seeking for mka (matroska) file with cue sheet.[/+]on Jun 24, 2025
Yeah, some formats don't support accurate seeking. ape format also has this issue. To work around that the ffmpeg input plugin has to throw away some samples after seeking to the nearest "keyframe" before the desired timestamp, which would make seeking in those formats just (or almost) as accurate as in flac. Also this would automatically fix gapless playback issues with those formats since gapless playback in cmus depends on accurate seeking. That's why it works for flac which has accurate seeking.
I tried to implement this workaround some time ago and it worked for ape but broke mp3 (I did something wrong) therefore i abandoned it :)
So this issue is not related to cue sheets but is caused by inaccurate seeking in ffmpeg plugin
Activity
gavtroy commentedon Feb 15, 2025
I tried to reproduce this with an Atmos .mka and it seemed fine, so it could be a problem tied to seeking in the specific mka file that was being used. It seems less likely to be related to the cue sheet if it worked when converted to flac.
BoostCookie commentedon Feb 15, 2025
I have this problem with each of my Atmos files (underlying codec is TrueHD). And I also have the same problem with an mka file that has DTS inside.
There's nothing I can do wrong with my cue files for gapless to stop working, right? Because you only ever specify the starting timestamp of a song, and never the end.
ihy123 commentedon Feb 15, 2025
Hi, your Cue files look good. Did you try using them with other players?
BoostCookie commentedon Feb 15, 2025
Can you recommend a player I can test? The only other player I have is deadbeef and it does not like mka files.
ihy123 commentedon Feb 15, 2025
Try Audacious, it has ffmpeg plugin too
BoostCookie commentedon Feb 15, 2025
OK, I've now tried Audacious. It does not like TrueHD, but it can play my mka files with DTS inside. And it has the exact same seeking problem.
ihy123 commentedon Feb 15, 2025
So I assume it's either ffmpeg or broken file problem.
You can also try ffplay to make sure:
ffplay -ss 1.1 file.mka^ play file.mka starting from 1.1 sec
BoostCookie commentedon Feb 15, 2025
Can a file be broken in such a way that a full playback (with mpv or vlc) works perfectly fine, but when trying to accurately seek via a cue file it fails?
OK, maybe you're onto something. Just running
mkvmerge -o newfile.mka oldfile.mkaimproves the situation massively. Now the seeking is only a few milliseconds late which makes normal playback of a song pretty much OK, but the transition from one song to the next sounds still a bit stuttery. With the old file the transitions were unbearable (imagine skipping a second at the beginning of each song).EDIT: According to
ffprobethe old file has"time_base": "1/1000"while the new one has"time_base": "651/31250000"The seek of ffplay with the old file is actually a bit too early (as opposed to the one by cmus and audacious which is a bit too late). With the new one it seems spot on (or at least as spot on as cmus now.)
ihy123 commentedon Feb 16, 2025
time_base should be equal 1/sample_rate (1/48000 in your case). If you try running ffprobe on your flac file, you'll see correct time_base. That's probably why seeking works perfectly for flac. I don't know how to change time_base of .mka though
BoostCookie commentedon Feb 16, 2025
Oh my god, you're right. If I put the flac stream into an mka container then mkvmerge also gives it a time_base of 651/31250000 and cmus is slightly inaccurate when seeking.
So now I need to find out why mkvmerge sets it to this value and how to change it. I'll update when I know more.
BoostCookie commentedon Jun 23, 2025
Update: mkv and mka files only support nanosecond timestamps.
https://www.matroska.org/technical/notes.html
Neither audio with 44100 samples/s nor audio with 48000 samples/s has an integer number of ns between two frames. Therefore seeking will always be inaccurate.
Suggestion: When going from track n to track n+1, and both tracks are in the same file, then cmus should not seek the start of track n+1, but instead continue playing the file.
[-]No gapless playback and bad seeking for mka file with Dolby Atmos and cue sheet.[/-][+]No gapless playback and bad seeking for mka (matroska) file with cue sheet.[/+]ihy123 commentedon Jul 18, 2025
Yeah, some formats don't support accurate seeking. ape format also has this issue. To work around that the ffmpeg input plugin has to throw away some samples after seeking to the nearest "keyframe" before the desired timestamp, which would make seeking in those formats just (or almost) as accurate as in flac. Also this would automatically fix gapless playback issues with those formats since gapless playback in cmus depends on accurate seeking. That's why it works for flac which has accurate seeking.
I tried to implement this workaround some time ago and it worked for ape but broke mp3 (I did something wrong) therefore i abandoned it :)
So this issue is not related to cue sheets but is caused by inaccurate seeking in ffmpeg plugin