-
Notifications
You must be signed in to change notification settings - Fork 1
/
sports1m_shorten.py
40 lines (28 loc) · 1.08 KB
/
sports1m_shorten.py
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
import os
import argparse
import subprocess
import pprint
import shutil
parser = argparse.ArgumentParser()
parser.add_argument('--indir', type=str, required=True)
parser.add_argument('--outdir', type=str, default='./output')
parser.add_argument('--start_index', type=int, default=0)
parser.add_argument('--end_index', type=int, default=None)
opt = parser.parse_args()
pprint.pprint(vars(opt), indent=2)
input_filenames = sorted(os.listdir(opt.indir))
def shorten_vid(filename):
basename, _ = os.path.splitext(filename)
inputfile = os.path.join(opt.indir, filename)
command = ('ffmpeg -i {inp} -t 00:01:00.000 -c copy '
'{out}/{name}'.
format(inp=inputfile, out=opt.outdir, name=filename))
try:
subprocess.run(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
print('Error shortening video')
print(e)
return
print('Shortened %s' % filename)
list(map(shorten_vid, input_filenames[opt.start_index:opt.end_index]))