Skip to content

No gapless playback and bad seeking for mka (matroska) file with cue sheet. #1397

Closed

Description

@BoostCookie

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.

  1. 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
  1. cmus --version:
cmus v2.12.0
Copyright 2004-2006 Timo Hirvonen
Copyright 2008-2016 Various Authors
  1. cmus --plugins:
Input Plugins: /usr/lib/cmus/ip
  mad:
    Default Priority: 55
    File Types: mp3 mp2
    MIME Types: audio/mpeg audio/x-mp3 audio/x-mpeg
  aac:
    Default Priority: 50
    File Types: aac
    MIME Types: audio/aac audio/aacp
  cdio:
    Default Priority: 50
    File Types:
    MIME Types: x-content/audio-cdda
  cue:
    Default Priority: 50
    File Types:
    MIME Types: application/x-cue
  flac:
    Default Priority: 50
    File Types: flac fla
    MIME Types:
  modplug:
    Default Priority: 50
    File Types: mod s3m xm it 669 amf ams dbm dmf dsm far mdl med mtm okt ptm stm ult umx mt2 psm
    MIME Types:
  mpc:
    Default Priority: 50
    File Types: mpc mpp mp+
    MIME Types: audio/x-musepack
  opus:
    Default Priority: 50
    File Types: opus
    MIME Types:
  vorbis:
    Default Priority: 50
    File Types: ogg oga ogx
    MIME Types: application/ogg audio/x-ogg
  wav:
    Default Priority: 50
    File Types: wav
    MIME Types:
  wavpack:
    Default Priority: 50
    File Types: wv
    MIME Types: audio/x-wavpack
  ffmpeg:
    Default Priority: 30
    File Types: aa aac ac3 aif aifc aiff ape au dsf fla flac m4a m4b mka mkv mp+ mp2 mp3 mp4 mpc mpp ogg opus shn tak tta wav webm wma wv
    MIME Types:

Output Plugins: /usr/lib/cmus/op
  pulse
  alsa
  oss
  jack
  ao

Activity

  1. gavtroy commented on Feb 15, 2025

    @gavtroy
    Collaborator

    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.

  2. BoostCookie commented on Feb 15, 2025

    @BoostCookie
    Author

    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.

  3. ihy123 commented on Feb 15, 2025

    @ihy123
    Contributor

    Hi, your Cue files look good. Did you try using them with other players?

  4. BoostCookie commented on Feb 15, 2025

    @BoostCookie
    Author

    Hi, your Cue files look good. Did you try using them with other players?

    Can you recommend a player I can test? The only other player I have is deadbeef and it does not like mka files.

  5. ihy123 commented on Feb 15, 2025

    @ihy123
    Contributor

    Try Audacious, it has ffmpeg plugin too

  6. BoostCookie commented on Feb 15, 2025

    @BoostCookie
    Author

    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.

  7. ihy123 commented on Feb 15, 2025

    @ihy123
    Contributor

    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

  8. BoostCookie commented on Feb 15, 2025

    @BoostCookie
    Author

    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.)

  9. ihy123 commented on Feb 16, 2025

    @ihy123
    Contributor

    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

  10. BoostCookie commented on Feb 16, 2025

    @BoostCookie
    Author

    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.

  11. BoostCookie commented on Jun 23, 2025

    @BoostCookie
    Author

    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.

  12. 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
  13. ihy123 commented on Jul 18, 2025

    @ihy123
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions