forked from FozzTexx/viddin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapterize
executable file
·63 lines (56 loc) · 1.71 KB
/
chapterize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#
# Copyright 2016 by Chris Osborn <[email protected]>
#
# This file is part of viddin.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at <http://www.gnu.org/licenses/> for
# more details.
import subprocess
import os
import datetime
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument("files", nargs="+", help="Video to join")
args = parser.parse_args()
lengths = [0]
for video in args.files:
curpos = lengths[-1]
cmd = "ffmpeg -i \"%s\" -f ffmetadata 2>&1 | grep 'Chapter #'" % video
last = 0
with os.popen(cmd) as f:
for line in f:
fields = line.split()
begin = float(re.sub(",", "", fields[3]))
len = begin - last
lengths.append(curpos + begin)
last = begin
cmd = "vidinf \"%s\" | grep ID_LENGTH | sed -e 's/ID_LENGTH=//'" % video
process = os.popen(cmd)
len = float(process.read())
process.close()
lengths.append(curpos + len)
#lengths.pop()
lengths.pop(0)
print "CHAPTER01=00:00:00.00"
print "CHAPTER01NAME=Opening"
segnum = 1
pos = 0
for segpos in lengths:
# pos += 0.25
# pos += segpos
pos = segpos
offset = str(datetime.timedelta(seconds = pos))
offset = offset[:-4]
print "CHAPTER%02i=0%s" % (segnum + 1, offset)
print "CHAPTER%02iNAME=Chapter %i" % (segnum + 1, segnum)
segnum += 1