Page 2 of 3

Re: Labels to id3v2 mp3 chapters spec

Posted: Sat May 11, 2019 11:38 am
by vxm
ve4jhj wrote:
Sat May 11, 2019 2:40 am
vxm wrote:
Fri May 10, 2019 9:15 pm
Is a screen grab of mp3 chapters in VLC on Windows, taken from the Internet.
According to the Auphonic website where that image comes from, the image is showing Mp4 chapter marks, rather than MP3. MP3 Chapters are not supported in VLC on Windows based on my own testing using the files supplied by you, as well as the mp4 file supplied by Auphonic.
You're correct, I made a mistake, that image of VLC is showing MP4 chapters. I apologize. This explains why I was unable to verify it with my file on Mac, but had been reassured that it was there.

MP3 chapters are going to be supported by VLC:

https://trac.videolan.org/vlc/ticket/7485

shows that MP3 chapters support is fixed for 4.0 of VLC as of 3 months ago, and Auphonic was one of the commenters there.

Re: Labels to id3v2 mp3 chapters spec

Posted: Sat May 11, 2019 8:08 pm
by steve
By default, Audacity uses LAME for writing MP3s, but it appears that LAME does not support id3v2 chapter frames.

Audacity is able to use FFmpeg for exporting, but I've not yet found any documentation to confirm that FFmpeg supports writing MP3 Chapter frames (I've only found documentation about reading MP3 chapters).
This page appears to imply that it doesn't support writing chapter tags: https://wiki.multimedia.cx/index.php/FF ... tadata#MP3

This page says that FFmpeg does support writing MP3 chapter tags: https://auphonic.com/blog/2013/07/03/ch ... -podcasts/
Has anyone been able to find FFmpeg documentation to confirm this?

Re: Labels to id3v2 mp3 chapters spec

Posted: Mon May 13, 2019 3:23 am
by vxm
http://jonhall.info/create_id3_tags_using_ffmpeg/ discusses using an external FFMETADATA file to write out the tags to an mp3.

Code: Select all

;FFMETADATA1
title=Blondie, Steve Jobs, Jimmy Iovine & Jimmy Destri
encoded_by=auphonic.com
artist=AppleInsider Podcast
date=2019
encoder=Lavf58.27.103
[CHAPTER]
TIMEBASE=1/1000
START=6894
END=63195
title=Opener
[CHAPTER]
TIMEBASE=1/1000
START=63195
END=642776
title=Introduction: Jimmy Destri
[CHAPTER]
TIMEBASE=1/1000
START=642776
END=725725
title=I know music, and I know addiction
[CHAPTER]
TIMEBASE=1/1000
START=725725
END=839739
title=Analog synths to digital and laptops
[CHAPTER]
TIMEBASE=1/1000
START=839739
END=896416
title=Garageband
[CHAPTER]
TIMEBASE=1/1000
START=896416
END=963578
title=Today, anybody can make a record
[CHAPTER]
TIMEBASE=1/1000
START=963578
END=1057941
title=iTunes really covered our asses
[CHAPTER]
TIMEBASE=1/1000
START=1057941
END=1128428
title=Spotify
[CHAPTER]
TIMEBASE=1/1000
START=1128428
END=1149937
title=You trust Apple...
[CHAPTER]
TIMEBASE=1/1000
START=1149937
END=1333239
title=What is Facebook's responsibility to their users
[CHAPTER]
TIMEBASE=1/1000
START=1333239
END=1498748
title=Apple News
[CHAPTER]
TIMEBASE=1/1000
START=1498748
END=1700825
title=Who's going to be Apple's competitor in the future?
[CHAPTER]
TIMEBASE=1/1000
START=1700825
END=1744158
title=Steve Jobs parked anywhere he wants
[CHAPTER]
TIMEBASE=1/1000
START=1744158
END=1946689
title=Jimmy Iovine told me some Steve Jobs stories
Is what FFMPEG sees as the metadata when I read from the file created with Auphonic, which matches the format on the page linked above. It seems possible to write .mp3 with chapters using FFmpeg if that page is accurate.

Testing this, I saved the metadata above as metadata.txt. Then in my terminal, I issued the command:

./ffmpeg -i /Users/vmarks/Downloads/ai\ pod/ai\ pod\ destri.mp3 -i /Users/vmarks/Downloads/ai\ pod/metadata.txt -map_metadata 1 -c:a copy -id3v2_version 3 -write_id3v1 1 /Users/vmarks/Downloads/ai\ pod/out.mp3

which took a file that had no chapters (ai pod destri.mp3) and read in the metadata.txt file, creating the out.mp3 with chapters. It had one error in the process, "[mp3 @ 0x7fb0e1803800] Audio packet of size 523 (starting with 00FFFBA0...) is invalid, writing it anyway."

FFmpeg saved a new file (out.mp3) with tags that look like mp3 id3 chapters. If I use FFmpeg -I on that out.mp3 file, it reports the chapters are there, with exactly what was in the metadata.txt for it. I don't know how to address that error, and something's not perfect: when I open it in an application that supports chapters, they aren't present. Also, I can see that the times have shifted slightly for start and stop from my file that has chapters created properly. I need to figure out why that is, and figure out why it looks like they're present, but not in applications that do support them.

But this seems promising. Things I could improve on: I don't really understand FFmpeg. I'm just using syntax that was mentioned on the link at the top of this post, without knowing exactly what to expect. The metadata.txt? I used FFworks, a gui frontend to FFmpeg, to read the chapters from the previously created known-working mp3 file, and clicked on "edit metadata" and copied and pasted that into a text editor. I admit I'm stumbling a bit here, but it feels... close.

Re: Labels to id3v2 mp3 chapters spec

Posted: Mon May 13, 2019 8:47 am
by steve
vxm wrote:
Mon May 13, 2019 3:23 am
If I use FFmpeg -I on that out.mp3 file, it reports the chapters are there, with exactly what was in the metadata.txt for it.
...
when I open it in an application that supports chapters, they aren't present.
That's a shame - so close and yet so far :(

You might like to try experimenting with Audacity's command line export: https://manual.audacityteam.org/man/exp ... ogram.html
If you could get this to work with chapter tags, then we could be well on the way to a usable workaround. It would probably be relatively easy to create a plug-in to read labels and return the appropriate text to copy and paste into the "External Program" command text box.

----

I found some information about creating "iPod-compatible" chapter tags, but this is using MP4 tags rather than MP3:
https://wiki.archlinux.org/index.php/Audiobook

Re: Labels to id3v2 mp3 chapters spec

Posted: Sat May 18, 2019 5:29 pm
by vxm
Success.

./ffmpeg -i /Users/vmarks/Downloads/ai\ pod/ai\ pod\ destri.mp3 -i /Users/vmarks/Downloads/ai\ pod/metadata.txt -map_metadata 1 -codec copy -id3v2_version 3 -write_id3v1 1 /Users/vmarks/Downloads/ai\ pod/out.mp3

created an out.mp3 file, which does have chapters when I check in applications that support it like Marco Arment's Forecast.app https://overcast.fm/forecast

Now that this checks out, how do we get to
It would probably be relatively easy to create a plug-in to read labels and return the appropriate text to copy and paste into the "External Program" command text box.
I do not know how to create this plug-in to form a metadata.txt formatted file out of labels.

Re: Labels to id3v2 mp3 chapters spec

Posted: Sun May 19, 2019 1:18 am
by steve
What is your "metadata.txt" file?

Re: Labels to id3v2 mp3 chapters spec

Posted: Fri May 24, 2019 2:01 am
by vxm
the contents of metadata.txt is:

Code: Select all

;FFMETADATA1
title=Blondie, Steve Jobs, Jimmy Iovine & Jimmy Destri
encoded_by=auphonic.com
artist=AppleInsider Podcast
date=2019
encoder=Lavf58.27.103
[CHAPTER]
TIMEBASE=1/1000
START=6894
END=63195
title=Opener
[CHAPTER]
TIMEBASE=1/1000
START=63195
END=642776
title=Introduction: Jimmy Destri
[CHAPTER]
TIMEBASE=1/1000
START=642776
END=725725
title=I know music, and I know addiction
[CHAPTER]
TIMEBASE=1/1000
START=725725
END=839739
title=Analog synths to digital and laptops
[CHAPTER]
TIMEBASE=1/1000
START=839739
END=896416
title=Garageband
[CHAPTER]
TIMEBASE=1/1000
START=896416
END=963578
title=Today, anybody can make a record
[CHAPTER]
TIMEBASE=1/1000
START=963578
END=1057941
title=iTunes really covered our asses
[CHAPTER]
TIMEBASE=1/1000
START=1057941
END=1128428
title=Spotify
[CHAPTER]
TIMEBASE=1/1000
START=1128428
END=1149937
title=You trust Apple...
[CHAPTER]
TIMEBASE=1/1000
START=1149937
END=1333239
title=What is Facebook's responsibility to their users
[CHAPTER]
TIMEBASE=1/1000
START=1333239
END=1498748
title=Apple News
[CHAPTER]
TIMEBASE=1/1000
START=1498748
END=1700825
title=Who's going to be Apple's competitor in the future?
[CHAPTER]
TIMEBASE=1/1000
START=1700825
END=1744158
title=Steve Jobs parked anywhere he wants
[CHAPTER]
TIMEBASE=1/1000
START=1744158
END=1946689
title=Jimmy Iovine told me some Steve Jobs stories
Presume the start and end numbers are the same as labels exported to .txt, but multiplied by 1000, moving the decimal place.

Re: Labels to id3v2 mp3 chapters spec

Posted: Fri May 24, 2019 9:58 am
by steve
Tell me if I've got any of this wrong:

I assume that this part is standard to all metadata.txt files:

Code: Select all

;FFMETADATA1
title=
encoded_by=
artist=
date=
If so, we can make a GUI with text fields for title, encoded by, artist and date.
The command for creating a text (string) input widget is:

Code: Select all

;control variable "Text left" string "text right" "default text"

Code: Select all

[CHAPTER]
TIMEBASE=1/1000
START=1700825
END=1744158
title=Steve Jobs parked anywhere he wants
So the format for each chapter is:

Code: Select all

[CHAPTER]
TIMEBASE=<fraction> (multiplier for each of the time values, default = milliseconds)
START=<integer> (time in milliseconds when timebase=1/1000)
END=<integer> (time in milliseconds when timebase=1/1000)
title=<text> (chapter title / description)
I'm guessing that the timebase is usually 1/1000, and usually the same for each chapter.

We will also want a file browser button to set the location of the output file. This is probably the most complex of all of Nyquist's GUI widgets, and is described here: https://wiki.audacityteam.org/wiki/Nyqu ... ton_Widget

So if I'm correct about the above, our interface could be something like this (you can run this in the Nyquist Prompt to see what it looks like.)

Code: Select all

;version 4
;type tool
;codetype lisp
;name "Labels to Chapters"

;control timebase "Time base" int "" 1000 100 2000
;control title "Title" string "" ""
;control encodedby "Encoded by" string "" ""
;control artist "Artist" string "" ""
;control date "Date" string "" "2019"
;control filename "Save file as" file "" "*default*/metadata.txt" "Text file|*.txt;*.TXT|All files|*.*;*" "save,overwrite"

The "START", "END" and "title" we can read from the labels, so we don't need to do anything for those in the GUI.

Does that all look good so far?

Re: Labels to id3v2 mp3 chapters spec

Posted: Fri May 24, 2019 2:09 pm
by steve
Assuming that I got all that right in my previous post, this should create a correctly formatted "metadata.txt" file (Requires Audacity 2.3.2 or later).

Code: Select all

;version 4
;type tool
;codetype lisp
;name "Labels to Chapters"
;author "Steve Daulton"
;release 2.3.2
;copyright "Released under terms of the GNU General Public License version 2"

;control timebase "Time base" int "" 1000 100 2000
;control title "Title" string "" ""
;control encodedby "Encoded by" string "" ""
;control artist "Artist" string "" ""
;control date "Date" string "" "2019"
;control filename "Save file as" file "" "*default*/metadata.txt" "Text file|*.txt;*.TXT|All files|*.*;*" "save,overwrite"


(setf metadata
  (format nil ";FFMETADATA1~%~
              title=~a~%~
              encoded_by=~a~%~
              artist=~a~%~
              date=~a~%~
              encoder=Lavf58.27.103~%"
              title
              encodedby
              artist
              date))

;;  Get label data from first label track
(setf labels (second (first (aud-get-info "Labels"))))


(dolist (label labels)
  (setf chapter
    (format nil "[CHAPTER]~%~
                TIMEBASE=1/~a~%~
                START=~a~%~
                END=~a~%~
                title=~a~%"
                timebase
                (round (* timebase (first label)))
                (round (* timebase (second label)))
                (third label)))
  (string-append metadata chapter))


(setf fp (open filename :direction :output))
(format fp metadata)
(close fp)
(format nil "File written to~%~a" filename)

This code assumes that your chapters are marked using region labels in the first (or only) label track.

You can run the above code in the Nyquist Prompt for testing.

For more convenient use, save the code as a file and name it "labels-to-chapters.ny". Note that the ".ny" at the end is important. You can then install and enable the plug-in as described here (instructions for macOS): https://manual.audacityteam.org/man/ins ... st_install
When installed, the plug-in will appear in the "Tools" menu.

Re: Labels to id3v2 mp3 chapters spec

Posted: Fri May 24, 2019 10:54 pm
by vxm
I don't commonly use region labels, but instead just press command B to insert a marker, name it, and move on - it ends when the next one begins.

I can run the code from the Nyquist command prompt, but it will not install it as a plugin. I do not know why.

I'm not convinced I'm doing this right yet.