|
| 1 | +import sys |
| 2 | +import argparse # python2.7+ |
| 3 | + |
| 4 | +from pyAvTranscoder import avtranscoder as av |
| 5 | + |
| 6 | + |
| 7 | +def parseConfigFile( inputConfigFile, transcoder ): |
| 8 | + file = open( inputConfigFile, 'r' ) |
| 9 | + for line in file: |
| 10 | + line = line.strip( '\n' ) |
| 11 | + |
| 12 | + filename, operation = line.split( '=' ) |
| 13 | + |
| 14 | + streamIndexes, profileName = operation.split( ':' ) |
| 15 | + if "." in streamIndexes: |
| 16 | + streamIndex, subStreamIndex = map(int, streamIndexes.split( '.' )) |
| 17 | + else: |
| 18 | + streamIndex = int(streamIndexes) |
| 19 | + subStreamIndex = -1 |
| 20 | + |
| 21 | + transcoder.add( filename, streamIndex, subStreamIndex, profileName ) |
| 22 | + |
| 23 | + |
| 24 | +# Create command-line interface |
| 25 | +parser = argparse.ArgumentParser( |
| 26 | + prog='pythumbnail', |
| 27 | + description='''Generate jpeg thumbnail from video/image.''', |
| 28 | +) |
| 29 | + |
| 30 | +# requirements |
| 31 | +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.') |
| 32 | +parser.add_argument('outputFileName', help='The output media file.') |
| 33 | +# Parse command-line |
| 34 | +args = parser.parse_args() |
| 35 | + |
| 36 | +# setup avtranscoder |
| 37 | +logger = av.Logger().setLogLevel(av.AV_LOG_QUIET) |
| 38 | +av.preloadCodecsAndFormats() |
| 39 | + |
| 40 | +# create Transcoder |
| 41 | +ouputFile = av.OutputFile( args.outputFileName ) |
| 42 | +transcoder = av.Transcoder( ouputFile ) |
| 43 | + |
| 44 | +# parse configuration file |
| 45 | +parseConfigFile( args.configFileName, transcoder ) |
| 46 | + |
| 47 | +# initialize Transcoder |
| 48 | +transcoder.setProcessMethod( av.eProcessMethodLongest ) |
| 49 | + |
| 50 | +# Process transcode |
| 51 | +progress = av.ConsoleProgress() |
| 52 | +transcoder.process( progress ) |
0 commit comments