Created
May 4, 2024 09:17
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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