import re
import string
import os
f_out = open('/Users/mengwang/Downloads/HM-16.0/BDrate.txt', 'w+')
def searchResult(chunk, matchSyntax, index):
if re.search(matchSyntax, chunk):
splitWord = re.split(r'\s+', chunk)
#print chunk
#print splitWord[3]
matchWord = []
matchWord.append(splitWord[index])
return matchWord
def writeResult(result):
f_out.write("%-20s"%(result[0]))
f_out.write("%-10s"%(result[1]))
f_out.write("%-10s"%(result[2]))
f_out.write("%-10s"%(result[3]))
f_out.write("%-10s"%(result[4]))
f_out.write("\n")
rootdir = '/Users/mengwang/Downloads/HM-16.0/encResult'
list = os.listdir(rootdir)
for i in range(0,len(list)):
pathDir = os.path.join(rootdir,list[i])
if os.path.isfile(pathDir):
f = open(pathDir, 'r')
while 1:
chunk = f.readline()
if chunk == '':
break
matchWord = 'SUMMARY'
findResult = searchResult(chunk, matchWord, 0)
if findResult:
chunk1 = f.readline()
chunk2 = f.readline()
splitEncResult = re.split(r'\s+', chunk2)
print chunk2
print pathDir
BDRATE = []
BDRATE.append(splitEncResult[3])
BDRATE.append(splitEncResult[4])
BDRATE.append(splitEncResult[5])
BDRATE.append(splitEncResult[6])
BDRATE.append(pathDir)
writeResult(BDRATE)
HM的report格式和AVS不一樣,AVS可以直接定位到關鍵字然後做完分割就可以取到想要的數據,但是HM的關鍵字應該是summary那一行,對應的結果再summer的下下行,像這樣。
SUMMARY --------------------------------------------------------
Total Frames | Bitrate Y-PSNR U-PSNR V-PSNR YUV-PSNR
5 a 12700.6080 41.4903 43.6672 44.2743 42.1685
I Slices--------------------------------------------------------
Total Frames | Bitrate Y-PSNR U-PSNR V-PSNR YUV-PSNR
5 i 12700.6080 41.4903 43.6672 44.2743 42.1685
P Slices--------------------------------------------------------
Total Frames | Bitrate Y-PSNR U-PSNR V-PSNR YUV-PSNR
0 p nan nan nan nan nan
B Slices--------------------------------------------------------
Total Frames | Bitrate Y-PSNR U-PSNR V-PSNR YUV-PSNR
0 b nan nan nan nan nan
RVM: 0.000
Bytes written to file: 132329 (12703.584 kbps)
Total Time: 4.734 sec
對於python的格式化輸出一直不太熟:
%-10s代表輸出數據左對齊,右邊添加佔位符
%10s代表輸出數據右對齊,左邊添加佔位符
所以採用左對齊的形式,當數據位數比較多的時候,當前輸出應該留出足夠多的佔位符。