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.txtThen prepare a files.txt file used for concatenation:
for f in input_*.flac ; do echo "file '$f'" >> files.txt ; doneNow 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