Home > Wiki > ffmpeg Articles

All articles are licensed under CC0 1.0 making them public domain.

MP3 chapter markers (for podcasts) #

Last updated February 2021

Chapter markers are used in podcast players such as Apple's own for iOS/Mac and Overcast for iOS. It's currently poorly documented due to its relative newness (although sitting in the spec for decades).

  1. Create a metadata.txt file with all your podcast metadata:

    album=Harry's Private Feed
    artist=Harry's Private Feed
    title=Example Title
    comment=Example description
    lyrics-eng=Example description
    TLEN=1234000
    date=2021
    [CHAPTER]
    TIMEBASE=1/1000
    START=0
    END=1111000
    title=Chapter 1 Title
    [CHAPTER]
    TIMEBASE=1/1000
    START=1111000
    END=1234000
    title=Chapter 2 title
  2. Lengths are calculated by taking the time in seconds and multiplying by 1000. This tool is helpful in converting media timestamps (e.g. 1:23:45) to seconds.

  3. Insert the metadata into the mp3 file using the text file: ffmpeg -i input.mp3 -i metadata.txt -map_metadata 1 -c:a copy -id3v2_version 3 -write_id3v1 1 output.mp3

  4. output.mp3 will contain your metadata and chapter markers.

Further steps

  • To find out how other podcasts did other cool chapter tricks you can dump all mp3 metadata into a file to reproduce it yourself: ffmpeg -i input.mp3 -f ffmetadata out-metadata.txt

  • To write album artwork: ffmpeg -i input.mp3 -i test.png -map 0:0 -map 1:0 -c copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" output.mp3


H.265/HEVC encoding for Apple devices #

Last updated February 2021

H.265/HEVC is an encoder which can offer file size saving of 20%-50% while producing an equal quality picture.

QuickTime Player on Mac and the TV app on iOS/Mac require specific settings in order to play H.265/HEVC encoded video. This is further explained here.

Command

ffmpeg -c:v libx265 -preset fast -crf 28 -tag:v hvc1 -c:a eac3 -b:a 224k -i <source> <target>

Note: H.265/HEVC CRF 28 is equivalent to H.264 video at CRF 23 as per the FFmpeg wiki.


FLAC to MP3 #

Last updated February 2021

ffmpeg -y -ab 320k -map_metadata 0 -id3v2_version 3 -c:v copy -i <source .flac> <target .mp3>

Retains metadata and converts to a bitrate of 320k.

Whole Library Shell Script

I haven't tried this script in a while and I remember it being a little funky. You have been warned.

I use a hacked together script that encodes to MP3 and mimics the structure of a FLAC music library. It preserves metadata, only encodes/copies the files that are not present in the MP3 music library and copies MP3s that you have within your main FLAC library.

If you use it make sure you change every directory (not just those in the header) and beware it has only been tested under ZSH. Use it however you want, it's licensed under Zero-Clause BSD making it public domain.

#!/bin/zsh
SRC="/Users/user/Dropbox/Music/"
DST="/Users/user/Music/Converted/"
FULLSRC="$SRC$GLOB"

for file in /Users/user/Dropbox/Music/**/*.flac; do
    newfile="${file/$SRC/$DST}"
    newfile="${newfile/.flac/.mp3}"
    newdir="${newfile%/*}"
    if [ ! -f "$newfile" ]; then
        mkdir -p "$newdir"
        ffmpeg -y -i "$file" -ab 320k -map_metadata 0 -id3v2_version 3 -c:v copy "$newfile"
    fi
done

for file in /Users/user/Dropbox/Music/**/*.mp3; do
    newfile="${file/$SRC/$DST}"
    newdir="${newfile%/*}"
    if [ ! -f "$newfile" ]; then
        mkdir -p "$newdir"
        echo "$file -> $newfile"
        cp "$file" "$newfile"
    fi
done