Skip to content

Instantly share code, notes, and snippets.

@bokunodev
Created May 6, 2021 21:54
Show Gist options
  • Save bokunodev/bb48ad6ce65081e938eb73efa68a676c to your computer and use it in GitHub Desktop.
Save bokunodev/bb48ad6ce65081e938eb73efa68a676c to your computer and use it in GitHub Desktop.
auto split video into chapters
#!/usr/bin/python
import json, os
tracklist = [
"bird funeral [Introduction]",
"This is the happiness peace committee. [Introduction]",
"Unhappy Refrain [two of the switching]",
"Sugar Bits [switching of two]",
"Gakuen × ∀ssassinatioИ [two of the switching]",
"Immorality of flower [two of the switching]",
"Mad Lovers [two of the switching]",
"Secret police [switching of two]",
"Cantarella [Michiyuki]",
"Monday, shadow My Hana [Michiyuki]",
"Chaining Intention [four of the switching]",
"deep sea girl [switching of four]",
"Halo _ Hawayu [four of the switching]",
"1_6 ~out of gravity~ [four of the switching]",
"Crescent rider [switching of four]",
"Tell Your World [Switching of four]",
"One Night Girl [finale]",
"Thousand Sakura [finale]",
"SWEET MEMORIES [finale]",
"Orange intersection [finale]"]
# to generate the json file, use ffprobe.
# ffprobe -v error -show_chapters -print_format json > chapters.json
with open("chapters.json","r") as f:
js = json.load(f)
counter = 0
for each in js["chapters"]:
os.system(f"ffmpeg -v error -ss {each['start_time']} -i in.mkv -to {each['end_time']} -vn -c:a libmp3lame -q:a 3 -compression_level 0 -threads 2 -y 'chapters/{tracklist[x]}.mp3'")
counter += 1
print(f"{counter:02d} '{tracklist[x]}'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment