annotate python/ffslice.py @ 741:9681a0bd74d6

add utility for slicing video files
author Jeff Hammel <k0scist@gmail.com>
date Sun, 28 Jun 2015 11:56:13 -0700
parents
children f011ec45b8e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
741
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 slice a clip with `ffmpeg`:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 ffmpeg -ss <00:00:00> -t <sec> -i <input_file> -q 1 <output_file> #
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 --ss = start time ;
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 -t = length of video to create from the start time in seconds.
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 """
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 # imports
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 import argparse
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 import os
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 import subprocess
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 import sys
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 # module globals
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 __all__ = ['main', 'Parser']
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 here = os.path.dirname(os.path.realpath(__file__))
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 string = (str, unicode)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 def ensure_dir(directory):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 """ensure a directory exists"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 if os.path.exists(directory):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 assert os.path.isdir(directory)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 return directory
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 os.makedirs(directory)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 return directory
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 def convert_seconds_to_hhmmss(time_sec):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36 """converts `time_sec` to (hh,mm,ss)"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 hh = int(time_sec / 3600)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 mm = int((time_sec % 3600) / 60)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
40 ss = int((time_sec % 3600) % 60)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41 return (hh,mm,ss)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
44 def format_seconds_to_hhmmss(time_sec, separator=':'):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
45 """converts `time_sec` to string 'hh:mm:ss'"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
46 return separator.join(['{:0>2d}'.format(i)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
47 for i in convert_seconds_to_hhmmss(time_sec)])
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
48
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
49
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
50 def duration(clip, ffprobe='ffprobe'):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
51 """get the duration in seconds using `ffprobe` from ffmpeg"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
52
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
53 command = [ffprobe, clip]
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
54 assert os.path.exists(clip), "Missing clip, duration not available"
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
55
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
56 # probe the file
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
57 try:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
58 output = subprocess.check_output(command, stderr=subprocess.STDOUT)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
59 # (for some reason, ffprobe sends output to stderr)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
60 except subprocess.CalledProcessError as e:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
61 print (e.output)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
62 raise
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
63
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
64 duration = None
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
65 for line in output.splitlines():
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
66 # Parse the output of `ffprobe`
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
67 # look for a line like:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
68 # Duration: 00:00:59.73, start: 0.000000, bitrate: 7783 kb/s
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
69
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
70 line = line.strip()
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
71 if line.startswith("Duration:"):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
72 if duration:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
73 raise AssertionError("Duplicate duration - already found: {}".format(duration))
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
74 line = line.split(',')[0]
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
75 duration = line.split(':', 1)[1].strip()
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
76
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
77 if duration:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
78 hh, mm, ss = [float(i) for i in duration.split(':')]
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
79 duration = 3600*hh + 60*mm + ss
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
80
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
81 return duration
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
82
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
83
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
84 class FFSliceParser(argparse.ArgumentParser):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
85 """fflice CLI option parser"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
86
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
87 default_slice_time = 300.
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
88
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
89 def __init__(self):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
90 argparse.ArgumentParser.__init__(self, description=__doc__)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
91 self.add_argument('clips', metavar='clip', nargs='+', help="clips to slice")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
92 self.add_argument('-d', '--directory', dest='directory',
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
93 default=os.getcwd(),
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
94 help="output directory [DEFAULT: %(default)s]")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
95 self.add_argument('--durations', '--print-durations', dest='print_durations',
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
96 action='store_true', default=False,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
97 help="print durations and exit")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
98 self.add_argument('-n', dest='number', type=int,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
99 help="number of slices")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
100 self.add_argument('-t', '--time', dest='slice_time',
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
101 type=float,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
102 help="time of each slice [DEFAULT: {}]".format(self.default_slice_time))
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
103 self.add_argument('--dry-run', dest='dry_run',
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
104 action='store_true', default=False,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
105 help="print out what will be done")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
106 self.add_argument('--hhmmss', dest='hhmmss',
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
107 action='store_true', default=False,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
108 help="display times in 'hh:mm:ss' format; thedefault is in seconds")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
109
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
110 self.add_argument('-v', '--verbose', dest='verbose',
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
111 action='store_true', default=False,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
112 help="be verbose")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
113 self.options = None
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
114
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
115 def parse_args(self, *args, **kw):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
116 options = argparse.ArgumentParser.parse_args(self, *args, **kw)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
117 self.validate(options)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
118 self.options = options
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
119 return options
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
120
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
121 def validate(self, options):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
122 """validate options"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
123
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
124 missing = [clip for clip in options.clips
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
125 if not os.path.exists(clip)]
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
126 if missing:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
127 self.error("Not found: {}".format(', '.join(missing)))
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
128
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
129 if options.slice_time and options.number:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
130 self.error("Cannot specify slice time and number of slices")
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
131 # TODO: allow specification of both
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
132 elif options.slice_time is None and options.number is None:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
133 options.slice_time = self.default_slice_time
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
134
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
135 ensure_dir(options.directory)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
136
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
137 def format_seconds(self, seconds):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
138 """format seconds to string"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
139 if self.options.hhmmss:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
140 return format_seconds_to_hhmmss(seconds)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
141 return '{:.2}'.format(seconds)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
142
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
143
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
144 def main(args=sys.argv[1:]):
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
145 """CLI"""
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
146
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
147 # parse command line options
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
148 parser = FFSliceParser()
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
149 options = parser.parse_args(args)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
150
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
151 # compute durations
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
152 durations = {clip: duration(clip) for clip in options.clips}
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
153 if options.print_durations:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
154 returncode = 0
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
155 total = 0.
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
156 for clip in options.clips:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
157 _duration = durations[clip]
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
158 if _duration is None:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
159 print ("Duration not found: '{}'".format(clip))
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
160 returncode = 1
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
161 else:
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
162 print ('{} : {}'.format(clip,
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
163 parser.format_seconds(_duration)))
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
164 sys.exit(returncode)
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
165
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
166 if __name__ == '__main__':
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
167 main()
9681a0bd74d6 add utility for slicing video files
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
168