#!/bin/bash input_file="chapters.txt" output_file="chapters.ffmetadata" # Create the FFmetadata chapter file echo ";FFMETADATA1" > "$output_file" previous_seconds=0 while IFS="=" read -r timestamp chapter_name; do # Convert start time to seconds seconds=$(date -u -d "1970-01-01 $timestamp" +"%s") # Calculate the end time (previous chapter's start time) end_seconds=$previous_seconds # Update previous_seconds for the next iteration previous_seconds=$seconds echo "[CHAPTER]" >> "$output_file" echo "TIMEBASE=1/1000" >> "$output_file" echo "START=${end_seconds}000" >> "$output_file" echo "END=${seconds}000" >> "$output_file" echo "title=$chapter_name" >> "$output_file" done < "$input_file" echo "Chapter file '$output_file' created successfully." # Run FFmpeg to add chapters to the video ffmpeg -i input_video.mp4 -i chapters.ffmetadata -map_metadata 1 -c:v copy -c:a copy -y output_video.mp4