-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathpyprocessor.py
More file actions
53 lines (38 loc) · 1.58 KB
/
Copy pathpyprocessor.py
File metadata and controls
53 lines (38 loc) · 1.58 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
47
48
49
50
51
52
53
#!/usr/bin/env python
import argparse # python2.7+
from pyAvTranscoder import avtranscoder as av
def parseConfigFile( inputConfigFile, transcoder ):
file = open( inputConfigFile, 'r' )
for line in file:
line = line.strip( '\n' )
filename, operation = line.split( '=' )
streamIndexes, profileName = operation.split( ':' )
if "." in streamIndexes:
streamIndex, subStreamIndex = map(int, streamIndexes.split( '.' ))
else:
streamIndex = int(streamIndexes)
subStreamIndex = -1
transcoder.add( filename, streamIndex, subStreamIndex, profileName )
# Create command-line interface
parser = argparse.ArgumentParser(
prog='pythumbnail',
description='''Generate jpeg thumbnail from video/image.''',
)
# requirements
parser.add_argument('configFileName', help='The config file will be parsed by foloowing this pattern: <media_file>=<stream_index><.substream_index>:<profile_name> \nGenerated streams (video and audio) and offset are not supported.')
parser.add_argument('outputFileName', help='The output media file.')
# Parse command-line
args = parser.parse_args()
# setup avtranscoder
logger = av.Logger().setLogLevel(av.AV_LOG_QUIET)
av.preloadCodecsAndFormats()
# create Transcoder
ouputFile = av.OutputFile( args.outputFileName )
transcoder = av.Transcoder( ouputFile )
# parse configuration file
parseConfigFile( args.configFileName, transcoder )
# initialize Transcoder
transcoder.setProcessMethod( av.eProcessMethodLongest )
# Process transcode
progress = av.ConsoleProgress()
transcoder.process( progress )