Created
January 26, 2022 11:27
-
-
Save nico-lab/49e0f4c589680184071916dcca2f3e71 to your computer and use it in GitHub Desktop.
https://ikyle.me/blog/2020/add-mp4-chapters-ffmpeg より時間とチャプター名からチャプターをつくるPythonスクリプト
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 re | |
chapters = list() | |
with open('chapters.txt', 'r') as f: | |
for line in f: | |
x = re.match(r"(\d):(\d{2}):(\d{2}) (.*)", line) | |
hrs = int(x.group(1)) | |
mins = int(x.group(2)) | |
secs = int(x.group(3)) | |
title = x.group(4) | |
minutes = (hrs * 60) + mins | |
seconds = secs + (minutes * 60) | |
timestamp = (seconds * 1000) | |
chap = { | |
"title": title, | |
"startTime": timestamp | |
} | |
chapters.append(chap) | |
text = "" | |
for i in range(len(chapters)-1): | |
chap = chapters[i] | |
title = chap['title'] | |
start = chap['startTime'] | |
end = chapters[i+1]['startTime']-1 | |
text += f""" | |
[CHAPTER] | |
TIMEBASE=1/1000 | |
START={start} | |
END={end} | |
title={title} | |
""" | |
with open("FFMETADATAFILE", "a") as myfile: | |
myfile.write(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment