Opened 4 years ago

Last modified 3 years ago

#8728 open defect

Misplaced chapters for mp3 files (ID3v2 Chapter Frame Addendum)

Reported by: sandreas Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: chapters, mp3, misplaced
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

When i use ffmpeg to export ffmetadata of an mp3 file with chapter and then reimport the same ffmetadata, the chapters timestamps are different.

  1. download the media file https://send.firefox.com/download/efb4d882f95b99bd/#gbNb7ZUVFxrVWDSobvZvYg
  1. create a file ffmeta.txt with the following contents:
    ;FFMETADATA1
    title=01 - Preface.
    
    album=History of a Six Weeks' Tour
    
    genre=Speech
    
    artist=Percy Bysshe Shelley
    
    track=1
    
    encoder=Lavf58.29.100
    
    [CHAPTER]
    TIMEBASE=1/1000
    START=0
    END=196437
    title=01 - Preface.
    [CHAPTER]
    TIMEBASE=1/1000
    START=196437
    END=381591
    title=02 - Author's Introduction.
    [CHAPTER]
    TIMEBASE=1/1000
    START=381591
    END=1712027
    title=03 - France.
    [CHAPTER]
    TIMEBASE=1/1000
    START=1712027
    END=2653177
    title=04 - Switzerland.
    [CHAPTER]
    TIMEBASE=1/1000
    START=2653177
    END=3279154
    title=05 - Germany.
    [CHAPTER]
    TIMEBASE=1/1000
    START=3279154
    END=3640978
    title=06 - Holland.
    [CHAPTER]
    TIMEBASE=1/1000
    START=3640978
    END=4214143
    title=07 - Letters Written During a
    [CHAPTER]
    TIMEBASE=1/1000
    START=4214143
    END=4657969
    title=08 - Letters Written During a
    [CHAPTER]
    TIMEBASE=1/1000
    START=4657969
    END=6200600
    title=09 - Letters Written During a
    [CHAPTER]
    TIMEBASE=1/1000
    START=6200600
    END=7782426
    title=10 - Letters Written During a
    [CHAPTER]
    TIMEBASE=1/1000
    START=7782426
    END=8352603
    title=11 - Mont Blanc. Lines Written
    
  1. import the ffmeta.txt chapters by:
    'ffmpeg' '-hide_banner' '-i' 'merged.mp3' '-i' 'ffmeta.txt' '-map_metadata' '1' 'merged.new.mp3'
    
  1. export a new ffmeta-after-import.txt from the file just imported:
    'ffmpeg' '-hide_banner' '-i' 'merged.new.mp3' '-f' 'ffmetadata' 'ffmeta-after-import.txt'
    
  1. diff ffmeta.txt and ffmeta-after-import.txt

Because the chapters did not change between import and export, i would expect, that the chapters are at the same time, but the times are different. ffmpeg seems to change something here while importing chapters, whatever the reason is...

Change History (3)

comment:1 by mkver, 3 years ago

Status: newopen
  1. Your file is gone; you should have uploaded it here or attached it to this ticket in case of small samples.
  2. A quick test of mine shows that the chapters are offset by an amount corresponding to encoder delay. In fact, if one has an mp3 file with chapters and a xing frame indicating encoder delay, then each round of remuxing (without reencoding) offsets the chapters by this encoder delay. The demuxer just signals the encoder delay via side data and the AVStream's start_time. It is ffmpeg that offsets the chapters to (presumably) somehow compensate for this. This is definitely a bug (regardless of the missing sample).

in reply to:  1 comment:2 by sandreas, 3 years ago

Replying to mkver:

  1. Your file is gone; you should have uploaded it here or attached it to this ticket in case of small samples.
  2. A quick test of mine shows that the chapters are offset by an amount corresponding to encoder delay. In fact, if one has an mp3 file with chapters and a xing frame indicating encoder delay, then each round of remuxing (without reencoding) offsets the chapters by this encoder delay. The demuxer just signals the encoder delay via side data and the AVStream's start_time. It is ffmpeg that offsets the chapters to (presumably) somehow compensate for this. This is definitely a bug (regardless of the missing sample).

Thank yo for looking into this. The file is 33MB, so attachment did not work. The size is intended, with smaller files the issue is not fully reproducible. I uploaded the file to Videolan with reference project ffmpeg and gitlab ticket #8728, but it did not give me a reference to post here... As you already pointed out, it happens with the most mp3 files that have chapters and should be easily reproducible using a merged version of https://librivox.org/history-of-a-six-weeks-tour-by-percy-bysshe-shelley/ (I used https://github.com/sandreas/m4b-tool/ with m4b-tool merge audio_book_folder/ -o merged.mp3 --audio-channels 1 --audio-format mp3 --audio-bitrate 64k, but it can also be done with raw ffmpeg, if you import the chapters correctly).

comment:3 by mkver, 3 years ago

Your file is available here.

Note: See TracTickets for help on using tickets.