Skip to content

Instantly share code, notes, and snippets.

@jmb
Created May 4, 2024 09:17
Show Gist options
  • Save jmb/4d4b15a11a4f41dae99dee3d0f15a66e to your computer and use it in GitHub Desktop.
Save jmb/4d4b15a11a4f41dae99dee3d0f15a66e to your computer and use it in GitHub Desktop.
A Python script to obtain chapter titles and timestamps from a media file (uses ffprobe)
import json, argparse, subprocess
parser = argparse.ArgumentParser()
parser.add_argument('file')
args = parser.parse_args()
output = subprocess.run(["ffprobe", "-print_format", "json", "-show_chapters", "-sexagesimal", args.file], capture_output=True)
print(output)
data = json.loads(output.stdout)
for chapter in data['chapters']:
start_time, milliseconds = chapter['start_time'].split('.')
print(f"{start_time} {chapter['tags']['title']}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment