def RunFlatFixedViewTest(good, bad): (cy, cp) = good (cyBad, cpBad) = bad goodCenter = (cy, cp, 0) badCenter = (cyBad, cpBad, 0) closestQec = LayoutGenerators.QEC.GetClosestQecFromTestQec(cy, cp) (i, j) = closestQec.GetTileCoordinate() qecId = closestQec.GetStrId() (y, p, r) = closestQec.GetEulerAngles() #First we check if the output folder for this QEC exist: outputDirQEC = '{}/QEC{}'.format(outputDir, qecId) if not os.path.isdir(outputDirQEC): os.makedirs(outputDirQEC) eqL = LayoutGenerators.EquirectangularLayout('Equirectangular') if reuseVideo: inputVideos = [ '{}/equirectangular.mkv'.format(outputDir), '{}/equirectangularTiled{}.mkv'.format(outputDir, qecId), averageNameVideo ] layoutsToTest = [[(eqL, None)], [(LayoutGenerators.EquirectangularTiledLayout('EquirectangularTiled{}'.format(qecId), closestQec), None, refWidth, refHeight)], \ [(lsAverage.layout, lsAverage.a)]] else: inputVideos = [inputVideo, inputVideo, inputVideo] layoutsToTest = [[(eqL, None)], [(eqL, None),(LayoutGenerators.EquirectangularTiledLayout('EquirectangularTiled{}'.format(qecId), closestQec), None, refWidth, refHeight)], \ [(eqL, None),(lsAverage.layout, lsAverage.a)]] for layoutId in ['CubMap', \ #'CubMapCompact', \ 'Pyramidal', \ 'RhombicDodeca']: storageName = '{}/{}{}_storage.dat'.format(outputDir, layoutId, qecId) layoutVideoName = '{}/{}{}.mkv'.format(outputDir, layoutId, qecId) ls = LayoutGenerators.LayoutStorage.Load(storageName) if reuseVideo: inputVideos.append(layoutVideoName) layoutsToTest.append([(ls.layout, ls.a)]) else: inputVideos.append(inputVideo) layoutsToTest.append([(eqL, None), (ls.layout, ls.a)]) #Test Good Layout flatFixedLayout = LayoutGenerators.FlatFixedLayout( 'FlatFixed{}_{}'.format(abs(cy), abs(cp)).replace('.', '_'), outputResolution[0], outputResolution[1], 110, goodCenter) GenerateVideo.ComputeFlatFixedQoE(config, trans, layoutsToTest, flatFixedLayout, 24, n, inputVideos, outputDirQEC, closestQec, (cy, cp), True) #Test Bad layout flatFixedLayout = LayoutGenerators.FlatFixedLayout( 'FlatFixed{}_{}'.format(abs(cyBad), abs(cpBad)).replace('.', '_'), outputResolution[0], outputResolution[1], 110, badCenter) GenerateVideo.ComputeFlatFixedQoE(config, trans, layoutsToTest, flatFixedLayout, 24, n, inputVideos, outputDirQEC, closestQec, (cyBad, cpBad), False)
def DichotomousSearch(trans, config, n, inputVideo, outputName, goalSize, layout, maxIteration): best = 0 bestSize = None count = maxIteration a_min = 0 a_max = 1 print('The goal size is ',goalSize, 'Bytes') try: if os.path.isfile(outputName+'_storage.dat') and os.path.isfile(outputName+'.mkv'): ls = LayoutGenerators.LayoutStorage.Load(outputName+'_storage.dat') if ls.nbFrames == n: count = 0 best = ls.a bestSize = abs(os.stat(outputName+'.mkv').st_size-goalSize) while count != 0: count -= 1 a = (a_max+a_min)/2.0 print ('Start test for a = ',a, ', a_min = ',a_min, ', a_max = ', a_max) layouts_a = [(LayoutGenerators.EquirectangularLayout('Equirectangular'), None), (layout, a)] GenerateVideo.GenerateVideo(config, trans, layouts_a, 24, n, inputVideo, '/tmp/search') size = os.stat('/tmp/search.mkv').st_size diffSize = abs(goalSize-size) if bestSize is None or bestSize > diffSize: bestSize = diffSize best = a shutil.copyfile('/tmp/search.mkv', outputName+'.mkv') shutil.copyfile(config, outputName+'_log.txt') print ('Current brest is a = ', best, ', diffsize = ', bestSize, ' bytes') if (size > goalSize): a_max = a elif (size < goalSize): a_min = a else: break print('Best = ',best, ', diffsize = ', bestSize, ' bytes') ls = LayoutGenerators.LayoutStorage(layout, best, n) ls.Dump(outputName+'_storage.dat') except KeyboardInterrupt: print('Received <ctrl-c>') sys.exit(1) finally: if os.path.isfile('/tmp/search.mkv'): os.remove('/tmp/search.mkv') if os.path.isfile(config): os.remove(config)
def GenerateVideo(config, trans, layouts_a, fps, nbFrames, inputVideo, outputId, bitrate=0): tmpVideo = '/tmp/tmp.mkv' lastName = None lastLayout = None lastA = None for (l,a) in layouts_a: lastName = l.GetName() lastLayout = l lastA = a proc = None try: with open(config, 'w') as cf: cf.write(GenerateConfigString(layouts_a, fps, bitrate, nbFrames, inputVideo, tmpVideo)) proc = sub.Popen([trans, '-c', config]) if proc.wait() != 0: print('Error while processing') return None shutil.move('/tmp/tmp1{}.mkv'.format(lastName), '{}.mkv'.format(outputId)) shutil.copy(config, '{}_log.txt'.format(outputId)) except KeyboardInterrupt: print('Received <ctrl-c>') proc.terminate() sys.exit(1) raise except Exception as inst: print (inst) raise finally: if os.path.isfile('/tmp/tmp1{}.mkv'.format(lastName)): os.remove('/tmp/tmp1{}.mkv'.format(lastName)) return LayoutGenerators.LayoutStorage(lastLayout, lastA, nbFrames)
try: #First we re-encode the original Equirectangular video for fair comparaison later outEquiNameStorage = '{}/equirectangular_storage.dat'.format(outputDir) outEquiNameVideo = '{}/equirectangular.mkv'.format(outputDir) outEquiId = '{}/equirectangular'.format(outputDir) skip = False if os.path.isfile(outEquiNameStorage) and os.path.isfile( outEquiNameVideo): ls = LayoutGenerators.LayoutStorage.Load(outEquiNameStorage) if n == ls.nbFrames: skip = True if not skip: ls = GenerateVideo.GenerateVideo( config, trans, [(LayoutGenerators.EquirectangularLayout('Equirectangular'), None)], 24, n, inputVideo, outEquiId) ls.Dump(outEquiNameStorage) #We get the resolution of the video ffmpegProcess = sub.Popen(['ffmpeg', '-i', outEquiNameVideo], stderr=sub.PIPE) regex = re.compile('.*\s(\d+)x(\d+)\s.*') for line in iter(ffmpegProcess.stderr.readline, b''): m = regex.match(line.decode('utf-8')) if m is not None: refWidth = int(m.group(1)) refHeight = int(m.group(2)) #for each QEC we compute the EquirectangularTiled layout associated + the other layout with a fixed bitrate for qec in LayoutGenerators.QEC.TestQecGenerator():