📄 mvcrunner.py
字号:
(config, viewNumber ))
configFileData.SetValue('OutputFile',MakeOutputFileNameForView
(config, viewNumber ))
configFileData.SetValue('ReconFile',MakeReconFileNameForView
(config, viewNumber ))
configFileData.SetValue('BasisQP',config.qp)
configFileData.SetValue('SequenceFormatString',
MakePViewHierarchicalBFormatString(config))
configFileData.SetValue('NumRefFrames',config.paramsForMVC['SizeOfGOP'])
configFileData.SetValue('DPBSize',config.paramsForMVC['SizeOfGOP'])
configFileData.SetValue('MaxRefIdxActiveBL0',2)
configFileData.SetValue('MaxRefIdxActiveBL1',2)
configFileData.SetValue('MaxRefIdxActiveP',1)
configFileData.SetValue('VFramePeriod',config.paramsForMVC['SizeOfGOP'])
configFileData.SetValue('ViewLevel',1)
configFileData.SetValue('CurrentViewId',viewNumber)
configFileData.SetValue('AddForwardViewRef',MakeReconFileNameForView
(config, referenceView))
configFileData.WriteConfigFile(configFileName)
decodingCommand = MakeDecodingCommand(
config, configFileData.GetValue('OutputFile'), viewNumber,
[MakeReconFileNameForView(config, referenceView)],[])
return MVCTask(taskName,taskCommand,config.workingDir,config.adminEmail,
viewNumber,decodingCommand)
def MakeBViewEncodingTask(config, arbitraryIndex, viewNumber,
previousRef, laterRef):
if ( AlreadyEncodedView(config, viewNumber) ):
return EmptyTask(config)
taskName = 'Encode sequence %i as view %i referencing (%i,%i) ' % (
arbitraryIndex, viewNumber, previousRef, laterRef)
configFileName = os.path.join(config.workingDir,
'seq_%i_as_view_%i_encoder.cfg'%(
arbitraryIndex, viewNumber))
taskCommand = GetEncoderExe(config) + ' -pf ' + configFileName
configFileData = JSVM_MVC_Config.ConfigFile( config.paramsForJSVM )
configFileData.SetValue('InputFile',MakeInputFileNameForView
(config, viewNumber ))
configFileData.SetValue('OutputFile',MakeOutputFileNameForView
(config, viewNumber ))
configFileData.SetValue('ReconFile',MakeReconFileNameForView
(config, viewNumber ))
configFileData.SetValue('BasisQP',config.qp)
configFileData.SetValue('SequenceFormatString',
MakeBViewHierarchicalBFormatString(config))
configFileData.SetValue('NumRefFrames',config.paramsForMVC['SizeOfGOP'])
configFileData.SetValue('DPBSize',config.paramsForMVC['SizeOfGOP'])
configFileData.SetValue('MaxRefIdxActiveBL0',2)
configFileData.SetValue('MaxRefIdxActiveBL1',2)
configFileData.SetValue('MaxRefIdxActiveP',1)
configFileData.SetValue('VFramePeriod',config.paramsForMVC['SizeOfGOP'])
configFileData.SetValue('ViewLevel',2)
configFileData.SetValue('CurrentViewId',viewNumber)
configFileData.SetValue('AddForwardViewRef',MakeReconFileNameForView
(config, previousRef))
configFileData.SetValue('AddBackwardViewRef',MakeReconFileNameForView
(config, laterRef))
configFileData.WriteConfigFile(configFileName)
decodingCommand = MakeDecodingCommand(
config, configFileData.GetValue('OutputFile'), viewNumber,
[MakeReconFileNameForView(config, previousRef)],
[MakeReconFileNameForView(config, laterRef)])
return MVCTask(taskName,taskCommand,config.workingDir,config.adminEmail,
viewNumber, decodingCommand)
def MakeDecodingCommand(config, compressedBitstream, viewNumber,
previousRefs, laterRefs):
"""
MakeDecodingCommand(config, compressedBitstream, viewNumber,
previousRefs, laterRefs):
config: The configuration file module continaing things like
config.paramsForMVC, config.paramsForJSVM, etc.
compressedBitstream: Name of .264 output file to decode.
viewNumber: View number for file to decode.
previousRefs: A list of .yuv files representing forward multiview
references used by the encoder.
laterRefs: A list of .yuv files representing backward multiview
references used by the encoder.
This function returns a string representing python commands to
execute to decode the given compressed bitstream.
"""
decCommand = [GetDecoderExe(config),compressedBitstream,
MakeDecodedFileNameForView(config,viewNumber)]
for ref in previousRefs + laterRefs:
decCommand.extend([ref,`config.paramsForJSVM['SourceWidth']`,
`config.paramsForJSVM['SourceHeight']`])
if (0 != config.paramsForMVC['SizeOfGOP'] and
len(previousRefs+laterRefs) > 0):
decCommand.extend([`config.paramsForMVC['SizeOfGOP']`])
decCommand.append(' 2>&1 | tee decoderOutput_for_view_%i.txt' % viewNumber)
result = 'decodingCommand = %s\n%s\n%s\n%s\n%s\n' % (
`string.join(decCommand,' ')`,
'pipeForCommand = os.popen(decodingCommand)',
'commandResult = pipeForCommand.read() # returns output of command',
'status = pipeForCommand.close() # will be None or integer error code',
'print "Decoding status=%s. (status=None means no errors)" % `status`')
return result
def MakeSingleViewHierarchicalBFormatString(config):
return MakeHierarchicalBFormatString(config,'I')
def MakePViewHierarchicalBFormatString(config):
return MakeHierarchicalBFormatString(config,'P')
def MakeBViewHierarchicalBFormatString(config):
return MakeHierarchicalBFormatString(config,'B')
def MakeHierarchicalBFormatString(config, viewType):
sizeOfGOP = config.paramsForMVC['SizeOfGOP']
baseLevelForViewType = { 'I' : 0, 'P' : 0, 'B' : 1 }
assert baseLevelForViewType.has_key(viewType), (
'Unknown view type %s; only view types in %s are allowed.' % (
viewType, `baseLevelForViewType.keys()`))
baseLevel = baseLevelForViewType[viewType]
numberOfNormalGOPs =(config.paramsForJSVM['FramesToBeEncoded']-1)/sizeOfGOP
finalGOPSize = (config.paramsForJSVM['FramesToBeEncoded']-1) % sizeOfGOP
if (12 == sizeOfGOP):
result = string.join([
'A0',
' * %i{' %numberOfNormalGOPs,
'%s11 L%i' % (viewType, 0 + baseLevel),
'B5 L%i ' % (1 + baseLevel),
'B2 L%i ' % (2 + baseLevel),
'B8 L%i ' % (2 + baseLevel),
'B0 L%i' % (3 + baseLevel),
'b1 L%i' % (4 + baseLevel),
'B3 L%i' % (3 + baseLevel),
'b4 L%i' % (4 + baseLevel),
'B6 L%i' % (3 + baseLevel),
'b7 L%i' % (4 + baseLevel),
'B9 L%i' % (3 + baseLevel),
'b10 L%i' % (4 + baseLevel),
'}',
MakeFinalGOPOfSize( finalGOPSize, viewType, baseLevel ),
],'')
elif (15 == sizeOfGOP):
result = string.join([
'A0'
' * %i{' % numberOfNormalGOPs,
'%s14 L%i' % (viewType, 0 + baseLevel),
'B7 L%i' % (1 + baseLevel),
'B3 L%i' % (2 + baseLevel),
'B11 L%i' % (2 + baseLevel),
'B1 L%i' % (3 + baseLevel),
'B5 L%i' % (3 + baseLevel),
'B9 L%i' % (3 + baseLevel),
'B13 L%i' % (3 + baseLevel),
'b0 L%i' % (4 + baseLevel),
'b2 L%i' % (4 + baseLevel),
'b4 L%i' % (4 + baseLevel),
'b6 L%i' % (4 + baseLevel),
'b8 L%i' % (4 + baseLevel),
'b10 L%i' % (4 + baseLevel),
'b12 L%i' % (4 + baseLevel),
'}',
MakeFinalGOPOfSize( finalGOPSize, viewType, baseLevel ),
],'')
else:
raise '\n' + ( 'Do not know how to make single view hierarchical B\n' +
'SequenceFormatString for GOP with size %i.\n\n' %
sizeOfGOP)
return re.sub('\s','',result) # strips out white-space from result
def MakeFinalGOPOfSize( finalGOPSize, viewType, baseLevel ):
if (0 == finalGOPSize):
return ''
elif (14 == finalGOPSize):
return string.join([
'* 1{',
'%s13 L%i' % (viewType, 0 + baseLevel),
'B7 L%i' % (1 + baseLevel),
'B3 L%i' % (2 + baseLevel),
'B11 L%i' % (2 + baseLevel),
'B1 L%i' % (3 + baseLevel),
'B5 L%i' % (3 + baseLevel),
'B9 L%i' % (3 + baseLevel),
'b0 L%i' % (4 + baseLevel),
'b2 L%i' % (4 + baseLevel),
'b4 L%i' % (4 + baseLevel),
'b6 L%i' % (4 + baseLevel),
'b8 L%i' % (4 + baseLevel),
'b10 L%i' % (4 + baseLevel),
'b12 L%i' % (4 + baseLevel),
'}'],'')
elif (9 == finalGOPSize):
return string.join([
'* 1{',
'%s8 L%i' % (viewType, 0 + baseLevel),
'B4 L%i' % (1 + baseLevel),
'B6 L%i' % (2 + baseLevel),
'B2 L%i' % (2 + baseLevel),
'B0 L%i' % (3 + baseLevel),
'b1 L%i' % (4 + baseLevel),
'b3 L%i' % (4 + baseLevel),
'b5 L%i' % (4 + baseLevel),
'b7 L%i' % (4 + baseLevel),
'}'],'')
elif (6 == finalGOPSize):
return string.join([
'* 1{',
'%s5 L%i' % (viewType, 0 + baseLevel),
'B3 L%i' % (1 + baseLevel),
'B1 L%i' % (2 + baseLevel),
'b0 L%i' % (3 + baseLevel),
'b2 L%i' % (3 + baseLevel),
'b4 L%i' % (3 + baseLevel),
'}'],'')
else:
raise 'Do not know how to make final GOP of size %i.' %finalGOPSize
class MVCTask:
"""
An instance of the MVCTask class represents a task that must be
done (e.g., encoding, view syntheis, depth map extraction, etc.).
"""
def __init__(self,name,command,workingDir,adminEmail,viewNumber,
decodingCommand):
for item in ['name','command','workingDir','adminEmail','viewNumber',
'decodingCommand']:
self.__dict__[item] = locals()[item]
def Run(self,resultFile):
ImmediatePrint('Running task %s\n' % self.name)
ImmediatePrint('Running on node "%s".\n' % socket.gethostname())
if ('' != self.command.strip()):
self.result = DoCommand( self.command, printCommand=1,
writeResultToFile=resultFile,
adminEmail = self.adminEmail)
class EmptyTask(MVCTask):
def __init__(self,config):
MVCTask.__init__(self,name='Empty task',
command='echo doing empty task',
workingDir=config.workingDir,
adminEmail=config.adminEmail,
viewNumber=None,
decodingCommand='echo "fake decoding for empty task"')
def GetTracebackString(exc_info):
s = 'Traceback:\n'
for line in traceback.format_tb(exc_info[2]):
s = s + line
return s
Go()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -