首先通过ffmpeg输出每一帧的psnr比对值。
ffmpeg -i src.mp4 -i dst.mp4 -lavfi psnr="stats_file=psnr.log" -f null -
使用Matplotlib进行绘图,以下是示例代码。
import numpy as np
import matplotlib.pyplot as plt
log = 'psnr.log'
arr = []
fp = open(log)
for line in fp.readlines():
s = line.strip().split(' ')
k = s[5]
v = float(k.split(':')[1])
if v > 60 or v < 30:
continue
arr.append(v)
y = np.array(arr)
x = np.arange(0, len(y), 1)
c = np.mean(y)
c = np.around(c, 2)
plt.plot(x, y, label='psnr (dB)')
plt.title(log)
plt.xlabel('psnr avrage = ' + str(c) + ' dB', weight='bold')
plt.ylabel('psnr (dB)')
plt.ylim(30, 60)
#plt.axhline(y=c, color='b')
plt.legend(loc='lower left')
plt.show()