AIMP Forum

AIMP for Windows => Ошибки и замечания / Bugs => Обработано / Processed => Topic started by: JimD on January 26, 2024, 20:43:18

Title: [x] [2533] embedding mp3 chapters -- last chapter end time incorrect
Post by: JimD on January 26, 2024, 20:43:18
There is a problem with importing and embedding chapters into an mp3 audiobook file from a cue file. I am using AIMP for Windows v5.30.2533 (20.12.2023).

The problem is that the end time for the final chapter is not the correct value, but rather some very large (perhaps arbitrary) value that is many hours past the end of the file.

Input #0, mp3, from 'The Adventures of Sherlock Holmes.mp3':
  Metadata:
    album           : The Adventures of Sherlock Holmes
    composer        : Ralph Cosham
    title           : The Adventures of Sherlock Holmes
    artist          : Arthur Conan Doyle
    track           : 1
  Duration: 09:07:57.71, start: 0.000000, bitrate: 64 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 2835.000000
      Metadata:
        title           : A Scandal In Bohemia
    Chapter #0:1: start 2835.000000, end 5628.000000
      Metadata:
        title           : The Red-Headed League
    Chapter #0:2: start 5628.000000, end 7754.000000
      Metadata:
        title           : A Case Of Identity
    Chapter #0:3: start 7754.000000, end 10766.000000
      Metadata:
        title           : The Boscombe Valley Mystery
    Chapter #0:4: start 10766.000000, end 13121.000000
      Metadata:
        title           : The Five Orange Pips
    Chapter #0:5: start 13121.000000, end 16035.000000
      Metadata:
        title           : The Man With The Twisted Lip
    Chapter #0:6: start 16035.000000, end 18503.000000
      Metadata:
        title           : The Adventure Of The Blue Carbuncle
    Chapter #0:7: start 18503.000000, end 21585.000000
      Metadata:
        title           : The Adventure Of The Speckled Band
    Chapter #0:8: start 21585.000000, end 24118.000000
      Metadata:
        title           : The Adventure Of The Engineer's Thumb
    Chapter #0:9: start 24118.000000, end 26747.000000
      Metadata:
        title           : The Adventure Of The Noble Bachelor
    Chapter #0:10: start 26747.000000, end 29766.000000
      Metadata:
        title           : The Adventure Of The Beryl Coronet
    Chapter #0:11: start 29766.000000, end 4294966.296000
      Metadata:
        title           : The Adventure Of The Copper Beeches
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 64 kb/s
  Stream #0:1: Video: mjpeg (Progressive), yuvj420p(pc, bt470bg/unknown/unknown), 300x400 [SAR 72:72 DAR 3:4], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Cover (front)

Because of this, an audiobook player displays an incorrect length for the final chapter. The actual length of the last chapter should be about 54:36. See the attached screenshot ("MP3 Embedded Chapters Bug.png") from the Android app Listen Audiobook Player.

I have repeated the process to import chapters into an mp3 file from a cue file with the same result (both in this audiobook and in a couple of others). I do not have the same problem importing chapters into m4a or m4b files -- just mp3 files.

To correct this, the developer of this audiobook player is making a fix to the code in order to calculate the correct end time for mp3 audiobooks with embedded chapters, in case the chapters may have been imported from a cue file using AIMP.

The cue file that was used is included as an attachment below ("The Adventures of Sherlock Holmes.cue").
Title: Re: Bug in embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: ss.pl on January 27, 2024, 04:28:09
Duration: 09:07:57.71, start: 0.000000, bitrate: 64 kb/s

Добавьте в низ cue-файла

Code: [Select]
  TRACK 13 AUDIO
    TITLE "The END"
    INDEX 00 547:56:00
    INDEX 01 547:57:00

(https://www.aimp.ru/forum/index.php?action=dlattach;topic=72216.0;attach=70354)
Title: Re: Bug in embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: JimD on January 27, 2024, 13:42:17
I am sure that Sherlock Holmes would reject this solution, because AIMP already has all the information it needs internally to calculate the end time of the last chapter without forcing a false external workaround.
Title: Re: Bug in embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: ss.pl on January 27, 2024, 15:16:53
JimD, вы не предоставили файл для анализа. Только одни слова.
О каких претензиях к разработчику может быть речь?

Я сгенерировал такой файл (белый шум), и проверил работу плеера.
Всё работает корректно - аимп определяет размер последней главы.

Вот mp3-файл и cue-файл, без 13 трека.
https://mega.nz/folder/SeABEayT#Tt2wJD8FySA9Oz1RAlvGMg
Title: Re: Bug in embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: JimD on January 27, 2024, 16:24:35
Thank you for the test audiobook. I didn't include an actual example in my initial bug report because I had only copyrighted examples on hand and didn't want to expose them.

However, when I import and embed the chapters from your Holmes.cue file (without the added chapter 13) into your test Holmes.mp3 audiobook, I still find that the last chapter end time is incorrect. Here is the extract of embedded chapters using ffmpeg (note that I added title and other metadata using the AIMP tag editor, because AIMP would not embed chapters without it):

Input #0, mp3, from 'Holmes.mp3':
  Metadata:
    album           : The Adventures of Sherlock Holmes
    title           : The Adventures of Sherlock Holmes
    artist          : Sir Arthur Conan Doyle
    track           : 1
  Duration: 09:07:57.74, start: 0.025057, bitrate: 64 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 2835.000000
      Metadata:
        title           : A Scandal In Bohemia
    Chapter #0:1: start 2835.000000, end 5628.000000
      Metadata:
        title           : The Red-Headed League
    Chapter #0:2: start 5628.000000, end 7754.000000
      Metadata:
        title           : A Case Of Identity
    Chapter #0:3: start 7754.000000, end 10766.000000
      Metadata:
        title           : The Boscombe Valley Mystery
    Chapter #0:4: start 10766.000000, end 13121.000000
      Metadata:
        title           : The Five Orange Pips
    Chapter #0:5: start 13121.000000, end 16035.000000
      Metadata:
        title           : The Man With The Twisted Lip
    Chapter #0:6: start 16035.000000, end 18503.000000
      Metadata:
        title           : The Adventure Of The Blue Carbuncle
    Chapter #0:7: start 18503.000000, end 21585.000000
      Metadata:
        title           : The Adventure Of The Speckled Band
    Chapter #0:8: start 21585.000000, end 24118.000000
      Metadata:
        title           : The Adventure Of The Engineer's Thumb
    Chapter #0:9: start 24118.000000, end 26747.000000
      Metadata:
        title           : The Adventure Of The Noble Bachelor
    Chapter #0:10: start 26747.000000, end 29766.000000
      Metadata:
        title           : The Adventure Of The Beryl Coronet
    Chapter #0:11: start 29766.000000, end 4294966.296000
      Metadata:
        title           : The Adventure Of The Copper Beeches
  Stream #0:0: Audio: mp3, 44100 Hz, mono, fltp, 64 kb/s
      Metadata:
        encoder         : LAME3.100
Title: Re: Bug in embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: JimD on January 27, 2024, 16:33:01
I should have included the header portion of the ffmpeg runtime output, to confirm that I was using your sample:

C:\Users\jdish\Documents\My Media\MP3 Audiobooks\Upload\test>ffmpeg -i "Holmes.mp3" -f ffmetadata
ffmpeg version N-113427-g8c99a1429a-20240126 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 13.2.0 (crosstool-NG 1.25.0.232_c175b21)
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-shared --disable-static --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libharfbuzz --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libaribcaption --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --enable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20240126
  libavutil      58. 36.101 / 58. 36.101
  libavcodec     60. 38.100 / 60. 38.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 17.100 /  9. 17.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
  libpostproc    57.  4.100 / 57.  4.100
Trailing option(s) found in the command: may be ignored.
Input #0, mp3, from 'Holmes.mp3':
Title: Re: Problem embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: ss.pl on January 28, 2024, 02:05:31
JimD, я с помощью ATE прописал главы (время из cue-файла)
(https://i.ibb.co/26txtHm/00.png)
эти три плеера (aimp, potplayer, mpc-be) работают без ошибок:

(https://i.ibb.co/PTHJY7M/02.png) (https://i.ibb.co/KKV0z2v/03.png) (https://i.ibb.co/ctLfkmQ/04.png)

Holmes2: https://mega.nz/folder/KSIXAByC#ikct8Wey4-ZtOforz-belg
если запустить "mp3", то плеер будет читает главы (если "cue-файл" то плеер поделит файл на треки).
Title: Re: Problem embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: JimD on January 28, 2024, 16:52:44
The main issue, as reported in my initial post, is that the end time of the last chapter looks to be incorrect after AIMP imports and embeds the mp3 chapter information from the cue file.

This can cause a problem in audiobook players that display the length of each chapter (and the time remaining if it is currently playing). If the player depends on the end time (which looks incorrect in this instance), it will display the chapter length as a very large number of hours (see the attached screenshots). This could be confusing or even alarming to the user.

In the responses so far, no one has explicitly confirmed that the end time 4294966.296000 below (which I reported in the initial post) is correct or incorrect:

    Chapter #0:11: start 29766.000000, end 4294966.296000
      Metadata:
        title           : The Adventure Of The Copper Beeches

The correct end time, it seems to me, should be as follows (since that chapter actually has a length of 51:56):

    Chapter #0:11: start 29766.000000, end 32877.186754
      Metadata:
        title           : The Adventure Of The Copper Beeches

I ask that all further responses address specifically this issue, rather than offering workarounds (such as adding a fake last chapter to the cue file in order to trick the player) or implying that it doesn't really matter if the end time value is incorrect since the audiobook will simply stop playing at the end of the file.
Title: Re: Problem embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: Artem on January 29, 2024, 13:07:13
The main issue, as reported in my initial post, is that the end time of the last chapter looks to be incorrect after AIMP imports and embeds the mp3 chapter information from the cue file

Does AIMP displays the file duration correctly? The file duration is used for finish time of last chapter.
Of course, if you send to me an example (personally, may be), I will check all things by myself.
Title: Re: Problem embedding mp3 chapters from cue file -- last chapter end time incorrect
Post by: JimD on January 29, 2024, 15:46:50
Thank you for responding, Artem.

I will send you a private message containing a link to the original "Sherlock Holmes" mp3 audiobook as I received it from the source (which I'll mention to you there) so that you can go through the steps that I used to import and embed the chapters from the cue file. I will describe the steps in more detail there. (By the way, the problem affects not only this audiobook. I have also embedded into several other mp3 audiobooks, and the same problem of incorrect last chapter end time shows up. So it seems to be a general problem with mp3 audiobooks -- at least from that source.)

Attached with this current response are three images that I hope show the file duration information you requested:

"AIMP Chapters Editor (using cue, chapters not embedded)"
"AIMP Chapters Editor (chapters embedded in mp3)"
"AIMP Player (using cue)"

I don't know how to play the mp3 in AIMP in such a way that it uses the embedded chapters as a playlist, which would be useful as well.
Title: Re: [x] [2533] embedding mp3 chapters -- last chapter end time incorrect
Post by: Artem on January 31, 2024, 22:12:34
Thank you.
Please, try this build: https://disk.yandex.ru/d/b0rEjbYt606F_Q
Title: Re: [x] [2533] embedding mp3 chapters -- last chapter end time incorrect
Post by: JimD on January 31, 2024, 22:54:51
Yes, I'm happy to report that the last chapter now shows the correct end time:

    Chapter #0:11: start 29766.000000, end 32878.644000
      Metadata:
        title           : The Adventure Of The Copper Beeches

Thank you for a product that for many years has been excellent in all the functionality that it provides. You are a very exacting designer and developer.