?? createconfigfile.py
字號:
"""
This module provides the MakeConfigFile and WriteConfigFile functions
which can create a configuration file for the desired test and/or write
it to a file. Specifically, this module provides routines to make
the configuration files expected by MVCRunner.py. Note that MVCRunner.py
then uses the configuration file created by this module to create
further configuration files for the JSVM encoder/decoder and view
interpolation. Therefore the config file created by this module
is basically a master of all other config files created by mv_script.
See comments for MakeConfigFile and WriteConfigFile for details.
"""
import os, os.path
def MakeConfigFile(paramsForMVC, paramsForJSVM, mainMVCDir):
"""
MakeConfigFile(paramsForMVC, paramsForJSVM, mainMVCDir):
paramsForMVC: This is a dictionary of parameters required for the
multi-view video coder.
paramsForJSVM: This is a dictionary of parameters required by the
JSVM software.
mainMVCDir: This is the path to the main directory for this module.
Among other things, it is used to determine where the
JSVM executables are stored.
This function creates a configuration file by combining the values in
the various params*** arguments with the defaults. The body of this
function contains comments describing the various parameters. Only
parameters whose default values are None must be specified by the caller;
all other parameters will be set to reasonable defaults.
"""
# Following are parameters that control MVC but don't go in JSVM config file
configParamsForMVC = {
#
'SizeOfGOP' : None, # how big to make each GOP
#
# Describes what prediction structure to use. Can be one of
# {'SimpleHierarchicalB', }
'PredictionStructure' : None,
#
#
'NumExtraPViews' : 0, # How many P extra views to put before starting
# # mode named by PredictionStructure, e.g., if
# # NumExtraPViews=1 then a I P B P B ... view
# # structure will be used for SimpleHierarchicalB.
#
'SOURCEPATH' : None, # directory containing source sequences
#
#
'MakeLocalCopiesIfNecessary' : 0, # If this is true, then the exe and
# # input video files are copied to the
# # working directory.
#
# SEQUENCE provides the name of the sequence to code while
# SEQUENCE_NUMBERS provides a list of numbers for the sequences.
# For example, if SEQUENCE = 'ballroom_' and SEQUENCE_NUMBERS =[1,2,3]
# then the sequences ballroom_1, ballroom_2, and ballroom_3 in
# the directory named by SOURCEPATH will be encoded.
'SEQUENCE' : None,
'SEQUENCE_NUMBERS' : None,
#
#
# PREFIX is a prefix label to use for the output files.
#
'PREFIX' : 'MV_IBBP',
#
#
'BINPATH' : os.path.join(os.getcwd(),'..','bin') + os.sep,
#
# EncoderBinFile and DecoderBinFile are the names of the executables
# in the BINPATH directory to use for encoding and decoding.
#
'EncoderBinFile' : 'H264AVCEncoderLibTestStatic',
'DecoderBinFile' : 'H264AVCDecoderLibTestStatic',
#
'suffix' : '.yuv', # suffix after source files
#
'IViewDeltaQP' : 0, # modifier for QP for I views
#
#
# The alreadyEncodedViews entry contains a hash table where
# the keys are view numbers and the values are YUV files
# that have already been encoded. For example, if you had
# started encoding things for the ballroom sequence and
# crashed part way through, you might set this to
# { 0 : '/path/to/ballroom_0_recon.yuv',
# 1 : '/path/to/ballroom_0_recon.yuv' }
'alreadyEncodedViews' : {},
#
#
'IViewDeltaQP' : 0 # additional offset for I views
}
# Following are parameters that will go in the JM software config file.
# See the JM software documentation for a description of what these mean.
configParamsForJSVM = {
'FramesToBeEncoded' : 100,
'FrameRate' : 30.0,
'SourceWidth' : 640,
'SourceHeight' : 480,
}
for paramDictName in ['ParamsForMVC', 'ParamsForJSVM']:
paramDict = locals()['p'+paramDictName.lstrip('P')]
resultDict = locals()['config'+paramDictName]
for paramName in paramDict.keys():
resultDict[paramName] = paramDict[paramName]
for paramName in resultDict.keys():
if (None == resultDict[paramName]):
raise '\n\nNo value provided for parameter %s\n\t%s.\n\n' % (
('config%s[%s]' % (paramDictName,paramName)),
'This is value required')
return (configParamsForMVC, configParamsForJSVM)
def WriteConfigFile(configParamsForMVC, configParamsForJSVM, outputFile,
mainMVCDir, workingDir, qp, adminEmail,switchedWorkingDir):
"""
WriteConfigFile(configParamsForMVC, configParamsForJSVM, outputFile,
mainMVCDir, workingDir, qp, adminEmail,switchedWorkingDir):
This function calls MakeConfigFile and passes it the
configParamsForMVC, configParamsForJSVM, and
mainMVCDir parameters and writes the result to outputFile.
"""
fd = open(outputFile,'w')
(configParamsForMVC, configParamsForJSVM) = MakeConfigFile(
configParamsForMVC, configParamsForJSVM, mainMVCDir)
for paramDictName in ['configParamsForMVC', 'configParamsForJSVM']:
fd.write('p%s = {\n' % paramDictName.strip('configP'))
paramDict = locals()[paramDictName]
for key in paramDict.keys():
value = paramDict[key]
if (str == type(value)):
value = '"%s"' % value
else:
value = `value`
fd.write('\t%s : %s,\n' % (`key`,value))
fd.write('}\n\n\n')
fd.write('workingDir = %s\n\n' % `workingDir`)
fd.write('qp = %i\n\n' % qp)
fd.write('adminEmail = "%s"\n\n' % adminEmail)
fd.write('switchedWorkingDir = "%s"\n\n' % switchedWorkingDir)
fd.close()
def ValidateConfig(config):
"""
ValidateConfig(config):
config: A module representing a config file as generated by the
WriteConfigFile function.
This function does some simple sanity checking on the config
module and raises an exception if there is something wrong.
"""
for viewNum in config.paramsForMVC['alreadyEncodedViews'].keys():
reconFile = config.paramsForMVC['alreadyEncodedViews'][viewNum]
if (not os.path.exists(reconFile)):
raise 'File named by paramsForMVC["alreadyEncodedViews"][%i]\n%s'%(
viewNum, 'does not exist.')
reconFileLength = os.stat(reconFile)[6]
expectedLength = 3 * ( ( (config.paramsForJSVM['SourceHeight'] *
config.paramsForJSVM['SourceWidth']) / 2 ) *
config.paramsForJSVM['FramesToBeEncoded'] )
if (reconFileLength != expectedLength):
msg = ('File ' + paramsForMVC["alreadyEncodedViews"][i] + ' '
'named by paramsForMVC["alreadyEncodedViews"][' + `i` +']'+
(' has length %i instead of expected length %i.\n' %
(reconFileLength, expectedLength)))
raise msg
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -