-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathiframe.py
More file actions
46 lines (39 loc) · 1.05 KB
/
iframe.py
File metadata and controls
46 lines (39 loc) · 1.05 KB
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
'''
iframe.py - ffmpeg i-frame extraction
'''
import sys, getopt, os
import subprocess
# ffmpeg -i inFile -f image2 -vf "select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr oString%03d.png
def main(argv):
inFile = ''
oString = 'out'
usage = 'usage: python iframe.py -i <inputfile> [-o <oString>]'
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","oString="])
except getopt.GetoptError:
print usage
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print usage
sys.exit()
elif opt in ("-i", "--ifile"):
inFile = arg
elif opt in ("-o", "--oString"):
oString = arg
print 'Input file is "', inFile
print 'oString is "', oString
# need input, otherwise exit
if inFile == '':
print usage
sys.exit()
# start extracting i-frames
home = os.path.expanduser("~")
ffmpeg = home + '/bin/ffmpeg'
outFile = oString + '%03d.png'
cmd = [ffmpeg,'-i', inFile,'-f', 'image2','-vf',
"select='eq(pict_type,PICT_TYPE_I)'",'-vsync','vfr',outFile]
print cmd
subprocess.call(cmd)
if __name__ == "__main__":
main(sys.argv[1:])