TheMetalCenter / m4b-mp3-chapters-from-cuesheets

merge audiobooks or podcasts without re-encoding (remuxing only) to single m4b with quicktime/nero chapters or mp3 with id3v2 chapters using cuesheets; also allows for renaming/editing chapters
25 stars 0 forks source link
audiobook audiobooks chapters cue cuesheet ffmpeg id3v2 m4b mp3 podcast windows

m4b-mp3-chapters-from-cuesheets

Table of Contents

  1. Features
  2. Credit
  3. Dependencies
  4. General Work Flow
  5. Installation
  6. Working Files
  7. Usage Scenarios
  8. Tips & Tricks
  9. Troubleshooting Notes

Features:

Full credit to creators of borrowed scripts/software (included in repository for convenience will remove if asked):

Dependencies (Not included!) You will also need:

General Work Flow:

  1. Merge multiple audio files to a single mp3/mp4 file
  2. Obtain and edit cuesheet to add desired chapter info
    • generated by tracklist (from mp3tag) or pause detection (by mp3directcut)
  3. Convert .cue to ffmetadata then combine ffmetadata with mp3/mp4 file

Installation

Working files should be called:

Usage Scenarios:

Scenario 1: Creating single M4B file with embedded chapters from individual chapterized m4b files

1. Add m4b files to bin folder of ffmpeg (4.4 plus)
2. Import tracks into mp3tag
3. Edit "title" fields as desired (full chapter names will take longer than simple Chapter 01)
    - Ensure track number is filled and in order (can use mp3tag > tools > auto number wizard) 
    - Ensure the Artist field is not empty
    - Ensure the Album field contains no characters not allowed in a filename (?, :, etc)
4. Select all, right click > export > txt_taglist > Okay to create list.txt file
    - If this is first time, you will need to first edit "txt_taglist" and replace current text with below and save changes
        $filename(txt,utf-8)$loop(%_path%)%track%. "%title%" $div(%_length_seconds%,60)':'$num($mod(%_length_seconds%,60),2)
        $loopend()
5. Run m4b_merge-files.bat
    - will merge m4b files to a single input.mp4 file (make sure tracks are in proper order by filename)
6. Use "m4b_list2cue.bat"
    - will generate a .cue file
7. Run m4b_add-chapters.bat 
    - will add chapters then convert fmpeg embedded chapters to proper m4b quicktime format
    - will also attempt to rename and move output into its own folder based on album field

Scenario 2: Creating single MP3 file with embedded chapters from individual chapterized mp3 files

1. Add mp3 files to bin folder of ffmpeg (4.4 plus)
2. Import tracks into mp3tag
3. Edit "title" fields as desired (full chapter names will take longer than simple Chapter 01)
    - Ensure Tracknumber fields are filled with integers (can use mp3tag > tools > auto number wizard) 
    - Ensure the Artist field is not empty
    - Ensure the Album field contains no characters not allowed in a filename (?, :, etc)
4. Select all, right click > export > txt_taglist > Okay to create list.txt file
    - If this is first time, you will need to first edit "txt_taglist" and replace current text with below and save changes
        $filename(txt,utf-8)$loop(%_path%)%track%. "%title%" $div(%_length_seconds%,60)':'$num($mod(%_length_seconds%,60),2)
        $loopend()
5. Run mp3_merge-files.bat
    - will merge mp3 files to a single input.mp3 file (ensure tracks are in proper order by filename)
6. Use "mp3_list2cue.bat"
    - will generate a .cue file
7. Run mp3_add-chapters.bat 
    - will add chapters in id3v2.3 format
    - will also attempt to rename and move output into its own folder based on album field

Scenario 3: Creating single MP3 file with embedded chapters from randomly split mp3 files

1. Add mp3 files to bin folder of ffmpeg (4.4 plus)
2. Run mp3_merge-files.bat
    - will merge mp3 files to a single input.mp3 file (ensure tracks are in proper order by filename)
3. Drag merged input.mp3 into mp3directcut
4. Go to special > pause detection, try -44.5 dB, 2.9 s, -6 frames as a starting point
5. Wait for it to detect chapter breaks, click close once it no longer says "stop"
6. Check detected chapters with the >| dotted line button
    - If undercounts chapters, repeat step 4 with lower seconds or manually find chapters to add 
        - Note c creates a chapter but only if start and end point of selection are the same
        - this can be done quickly at position by hitting b, n, c
    - If it overcounts by a lot, repeat step 4 with higher seconds
    - Incorrect chapters can be deleted by selecting section, special > remove edit break
    - It is helpful to cross references number of chapters with numbers of pauses using epub
7. File > Save as cuesheet.cue
8. Open up .cue file in text editor and change TITLES as desired for each chapter 
9. Run mp3_add-chapters.bat 
    - will add chapters in id3v2.3 format
    - will also attempt to rename and move output into its own folder based on album field

Scenario 4: Creating single M4B file with embedded chapters from randomly split m4b files

0. Since mp3directcut doesn't support m4b we will make a *temporary* reencode to generate the .cue
1. Add m4b files to bin folder of ffmpeg (4.4 plus)
2. Run m4b_merge-files.bat
    - will merge m4b files to a single input.mp4 file (ensure tracks are in proper order by filename)
    - Remove old m4b files from the directory
3. Run m4b_reencode.bat
    - will rename the m4b file (if needed) to input.mp4 and reencode it to output.mp3
4. Drag reencoded mp3 file into mp3directcut
5. Go to special > pause detection, Try -44.5 dB, 2.9 s, -6 frames as starting point
6. Wait for it to detect chapter breaks, click close once it no longer says "stop"
7. Check detected chapters with the >| dotted line button
    - If undercounts chapters, repeat step 4 with lower seconds or manually find chapters to add 
        - Note c creates a chapter but only if start and end point of selection are the same
        - this can be done quickly at position by hitting b, n, c
    - If it overcounts by a lot, repeat step 4 with higher seconds
    - Incorrect chapters can be deleted by selecting section, special > remove edit break
    - It is helpful to cross references number of chapters with numbers of pauses using epub
8. File > Save as cuesheet.cue
9. Open up .cue file in text editor and change TITLES as desired for each chapter 
10. Once satisfied with your .cue, delete reencoded output.mp4
11. Run mp4_add-chapters.bat 
    - will add chapters then convert fmpeg embedded chapters to proper m4b quicktime format
    - will also attempt to rename and move output into its own folder based on album field

Scenario 5: Creating single M4B file that retains chapters from two m4b files with embedded chapters (can repeat if >2)

1. change the names of the two m4b files to be merged to input1.mp4 and input2.mp4
2. Run m4b_merge-chapterized.bat, which will merge the two files
    - will combine chapters then convert fmpeg embedded chapters to proper m4b quicktime format
    - will also remove extraneous video streams caused by embedded covers
3. Can check with ffmpeg -i *.m4b or MediaInfo to ensure chapters are present
4. If there is more than two m4b files, repeat steps for each additional part

Scenario 6: Changing existing embedded chapter titles in M4B or MP3

Export to Cue Sheet:    
1. Add the file to bin folder of ffmpeg (4.4 plus)
2. Rename the file to export.mp3 or export.m4b
3. Run mp3_export-cue.bat (or m4b)
4. Open cuesheet.cue and edit the chapter titles as desired
5. Rename to input.mp3 (or m4b)
6. Run mp3_add-chapter.bat (or m4b)
    - will add chapters in respective format
    - will also attempt to rename and move output into its own folder based on album field

Alternatively, you can export to Metadata:
1. Add the file to bin folder of ffmpeg (4.4 plus)
2. Rename the file to export.mp3 or export.m4b
3. Run mp3_export-metadata.bat or m4b_export-metadata.bat
4. Open metadata.txt and edit the chapter titles as desired
5. Rename the file to input.mp3 or input.mp4
6. Run mp3_mergemetadata.bat or mp4_merge-metadata.bat 
    - will overwrite existing chapters with edited chapters
    - will also attempt to rename and move output into its own folder based on album field

Tips & Tricks

Troubleshooting Notes