/
videoconvert
executable file
·126 lines (113 loc) · 3.93 KB
/
videoconvert
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
# Copyright (c) 2012 Oliver Burger obgr_seneca@mageia.org
#
# This file is part of videoconvert.
#
# videoconvert is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# videoconvert is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with videoconvert. If not, see <http://www.gnu.org/licenses/>.
videoconvertVersion = '0.1'
import os
import sys
import getopt
# self written imports
import videoconvert.Conf as Conf
import videoconvert.SystemCall as SystemCall
# check for the command line parameters
arguments = sys.argv
commandCall = arguments.pop(0)
optList, arguments = getopt.getopt(arguments, 'cvhr:f:', ['configure', 'resolution=',
'framerate=', 'container=', 'audiocodec=', 'videocodec=', 'keep', 'debug', 'help',
'version'])
configure=False
resolution=False
framerate=False
container=False
audioCodec=False
videoCodec=False
keep=False
debug=False
outputHelp=False
version=False
for param in optList:
if (param[0] == '--configure' or param[0] == '-c'):
configure=True
if (param[0] == '--keep'):
keep=True
if (param[0] == '--resolution' or param[0] == '-r'):
resolution=param[1]
if (param[0] == '--framerate' or param[0] == '-f'):
framerate=param[1]
if (param[0] == '--container'):
container=param[1]
if (param[0] == '--audiocodec'):
audioCodec=param[1]
if (param[0] == '--videocodec'):
videoCodec=param[1]
if (param[0] == '--debug'):
debug=True
if (param[0] == '--help' or param[0] == '-h'):
outputHelp=True
if (param[0] == '--version' or param[0] == '-v'):
version=videoconvertVersion
conf = Conf.Configuration(debug)
confFile = conf.getConfFile()
# if no config file exists or --configure or -c is given ask the user for his preffered settings
# otherwise read the config file
if (os.path.exists(confFile) == False or configure == True):
conf.getNewConfig()
else:
conf.readConfig()
# set parameters given on the command line
if framerate != False:
conf.setFramerate(framerate)
if resolution != False:
conf.setResolution(resolution)
if container != False:
conf.setContainer(container)
if audioCodec != False:
conf.setAudioCodec(audioCodec)
if videoCodec != False:
conf.setVideoCodec(videoCodec)
# read the remaining arguments from the command line
argumentIsGiven = False
if (len(arguments) >= 1 and outputHelp == False and version == False):
argumentIsGiven = True
isPath = True
if os.path.isdir(arguments[0]):
inDir = arguments.pop(0)
inFile = ''
elif os.path.isfile(arguments[0]):
inFile = arguments.pop(0)
inDir = ''
else:
isPath = False
if len(arguments) >= 1:
name = arguments.pop(0)
else:
name = 'videoconvert'
# if a directory is given try to sync vdr files in that directory and convert them
# if a file is given only convert it
if isPath:
systemCall = SystemCall.SystemCall(conf,keep,debug)
if inDir != '':
systemCall.sync(inDir,name)
elif inFile != '':
systemCall.convertFile(inFile,os.getcwd(),os.getcwd())
if ((argumentIsGiven == False or isPath == False) and outputHelp == False and version == False):
print 'Usage : '+commandCall+' [-c|--config] [--keep] [-f <framerate>|--framerate=<framerate>] [-r <resolution>|--resolution=<resolution>] <input directory> [<name>]'
if debug:
print conf.toString()
if outputHelp:
print 'Help, I need somebody\'s help...'
if version != False:
print 'videoconvert version ' + version