|
1 |
| -importargparse# python2.7+ |
| 1 | +#!/usr/bin/env python |
2 | 2 |
|
3 | 3 | frompyAvTranscoderimportavtranscoderasav
|
4 | 4 |
|
5 |
| -# Create command-line interface |
6 |
| -parser=argparse.ArgumentParser( |
7 |
| -prog='pythumbnail', |
8 |
| -description='''Generate jpeg thumbnail from video/image.''', |
9 |
| -) |
10 |
| - |
11 |
| -# requirements |
12 |
| -parser.add_argument('inputFileName',help='It could be any media file with at least one video stream (video, image...). Support file without extension.') |
13 |
| -# options |
14 |
| -parser.add_argument("-o","--outputFile",dest="outputFileName",default="thumbnail.jpg",help="Set the output filename (thumbnail.jpg by default). Must be with jpg extension!") |
15 |
| -parser.add_argument("-t","--time",dest="time",type=float,default=0,help="Set time (in seconds) of where to seek in the video stream to generate the thumbnail (0 by default).") |
16 |
| -parser.add_argument("-f","--frame",dest="frame",type=int,default=0,help="Set time (in frames) of where to seek in the video stream to generate the thumbnail (0 by default). Warning: priority to frame if user indicates both frame and time!") |
17 |
| -parser.add_argument("-w","--width",dest="width",type=int,default=0,help="Override the width of the thumbnail (same as input by default).") |
18 |
| -parser.add_argument("-he","--height",dest="height",type=int,default=0,help="Override the height of the thumbnail (same as input by default).") |
19 |
| -# Parse command-line |
20 |
| -args=parser.parse_args() |
| 5 | + |
| 6 | +# Get command line arguments |
| 7 | +args= [] |
| 8 | +try: |
| 9 | +# python2.7+ |
| 10 | +importargparse |
| 11 | + |
| 12 | +# Create command-line interface |
| 13 | +parser=argparse.ArgumentParser( |
| 14 | +prog='pythumbnail', |
| 15 | +description='''Generate jpeg thumbnail from video/image.''', |
| 16 | + ) |
| 17 | + |
| 18 | +# requirements |
| 19 | +parser.add_argument('inputFileName',help='It could be any media file with at least one video stream (video, image...). Support file without extension.') |
| 20 | +# options |
| 21 | +parser.add_argument("-o","--outputFile",dest="outputFileName",default="thumbnail.jpg",help="Set the output filename (thumbnail.jpg by default). Must be with jpg extension!") |
| 22 | +parser.add_argument("-t","--time",dest="time",type=float,default=0,help="Set time (in seconds) of where to seek in the video stream to generate the thumbnail (0 by default).") |
| 23 | +parser.add_argument("-f","--frame",dest="frame",type=int,default=0,help="Set time (in frames) of where to seek in the video stream to generate the thumbnail (0 by default). Warning: priority to frame if user indicates both frame and time!") |
| 24 | +parser.add_argument("-w","--width",dest="width",type=int,default=0,help="Override the width of the thumbnail (same as input by default).") |
| 25 | +parser.add_argument("-he","--height",dest="height",type=int,default=0,help="Override the height of the thumbnail (same as input by default).") |
| 26 | +# Parse command-line |
| 27 | +args=parser.parse_args() |
| 28 | + |
| 29 | +exceptImportError: |
| 30 | +importoptparse |
| 31 | + |
| 32 | +# Create command-line interface |
| 33 | +parser=optparse.OptionParser( |
| 34 | +usage='usage: %prog -i <file> -t|-f <time> [options]', |
| 35 | +prog='pythumbnail', |
| 36 | +description='''Generate jpeg thumbnail from video/image.''', |
| 37 | + ) |
| 38 | + |
| 39 | +# requirements |
| 40 | +parser.add_option("-i","--inputFile",dest='inputFileName',help='It could be any media file with at least one video stream (video, image...). Support file without extension.') |
| 41 | +# options |
| 42 | +parser.add_option("-o","--outputFile",dest="outputFileName",default="thumbnail.jpg",help="Set the output filename (thumbnail.jpg by default). Must be with jpg extension!") |
| 43 | +parser.add_option("-t","--time",dest="time",type="float",default=0,help="Set time (in seconds) of where to seek in the video stream to generate the thumbnail (0 by default).") |
| 44 | +parser.add_option("-f","--frame",dest="frame",type="int",default=0,help="Set time (in frames) of where to seek in the video stream to generate the thumbnail (0 by default). Warning: priority to frame if user indicates both frame and time!") |
| 45 | +parser.add_option("-w","--width",dest="width",type="int",default=0,help="Override the width of the thumbnail (same as input by default).") |
| 46 | +parser.add_option("--height",dest="height",type="int",default=0,help="Override the height of the thumbnail (same as input by default).") |
| 47 | +# Parse command-line |
| 48 | +args,other=parser.parse_args() |
| 49 | + |
| 50 | +ifargs.inputFileNameisNone: |
| 51 | +print"An input file is required. Use -i / --inputFile." |
| 52 | +exit(1) |
| 53 | + |
21 | 54 |
|
22 | 55 | # setup avtranscoder
|
23 | 56 | logger=av.Logger().setLogLevel(av.AV_LOG_QUIET)
|
|