This is a static render of the Sixohthree Wiki

Concatenating FLAC files with chapter markers

23rd April 2024 at 8:43pm

First, create a chapters.txt file of chapter markers, using time signatures from the source files:

START=0 ; echo ";FFMETADATA1" | tee chapters.txt ; for i in input_*.flac ; do echo -e "[CHAPTER]\nTIMEBASE=1/1\nSTART=${START}" ; END=$(ffprobe -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $i 2>/dev/null) ; START=$(($START+$END)) ; echo -e "END=${START}\n" ; done | tee -a chapters.txt

Then prepare a files.txt file used for concatenation:

for f in input_*.flac ; do echo "file '$f'" >> files.txt ; done

Now concatenate the files together in a matroska container, which supports chapter markers:

ffmpeg -y -f concat -i files.txt -i chapters.txt -map_metadata 1 -c copy output.mkv