-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsnr_analyzer.py
41 lines (34 loc) · 1.56 KB
/
psnr_analyzer.py
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
import subprocess
def get_hwdevice(hwaccel):
if hwaccel == "none":
return ""
else:
return hwaccel
class PsnrAnalyzer:
def __init__(self, ffmpeg_tools, hwaccel, output_dir):
self.ffmpeg_program = ffmpeg_tools + '/ffmpeg'
self.hwaccel = hwaccel
self.output_dir = output_dir
def analyze(self, transcode_file, origin_file, pnsr_report_name):
outputFile = self.output_dir + "/" + pnsr_report_name + ".log"
print("Start pnsr analyze")
print('Transcode file: {outputFile}'.format(outputFile=transcode_file))
print('Origin file: {outputFile}'.format(outputFile=origin_file))
print('Report file: {outputFile}'.format(outputFile=outputFile))
call_params = [self.ffmpeg_program]
hwaccels = get_hwdevice(self.hwaccel)
if(hwaccels):
call_params.append("-hwaccel")
call_params.append(hwaccels)
call_params.extend(["-i", transcode_file])
call_params.extend(["-i", origin_file])
call_params.extend([
"-filter_complex",
'[0:v]scale=1920x1080:flags=bicubic[main];[1:v]scale=1920x1080:flags=bicubic[ref];[main][ref]psnr={outputFile}'.format(outputFile=outputFile)])
# call_params.extend(["-lavfi", 'psnr=stats_file={outputFile}'.format(outputFile=outputFile)])
call_params.extend(["-f", "null"])
call_params.append("-")
print("Wait...")
subprocess.call(call_params, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
print("End analyze")
return outputFile