Skip to content

Instantly share code, notes, and snippets.

@daviehh
Forked from Bios-Marcel/mp3-chapters.md
Created June 30, 2021 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviehh/13e41df865a295956ee8421136cc30f5 to your computer and use it in GitHub Desktop.
Save daviehh/13e41df865a295956ee8421136cc30f5 to your computer and use it in GitHub Desktop.
Exporting Audacity labels to ID3v2+ chapter marks

Source: https://forum.audacityteam.org/viewtopic.php?f=20&t=104991&sid=0d7eadb4db3640283f6a33ac22307825&start=20

First of you need to install the following as a plugin in audacity:

;nyquist plug-in
;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 "" "2020"
;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 is the code that converts your label track into an ffmpeg-metadata file.

  1. Save the code as a .ny whereever you want to keep it or where you usually save your audacity plugins.
  2. Open Audacity
  3. Go to "Tools" -> "Nyquist Plug-in Installer..."
  4. Choose the file you saved in step one and confirm
  5. Under "Tools" -> "Add / Remove Plug-ins..." make sure the new plugin was successfully added and is enabled
  6. Create your audio file with the first label track serving as chapter marks
  7. When you are done, go to "Tools" and run the newly installed plug-in, saving the metadata.txt somewhere
  8. Export the audio as an mp3 file
  9. Open a terminal
  10. Run ffmpeg -i audio.mp3 -i metadata.txt -map_metadata 1 -codec copy -id3v2_version 3 -write_id3v1 1 audio-with-chapters.mp3

Don't simply copy the command, the file paths will differ ;)

While this solution isn't the most straightforward, you can at least edit your chapter marks in a GUI.

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