Skip to content

Instantly share code, notes, and snippets.

Created October 23, 2015 17:34
Show Gist options
  • Save anonymous/224c05f87f5bcddec634 to your computer and use it in GitHub Desktop.
Save anonymous/224c05f87f5bcddec634 to your computer and use it in GitHub Desktop.
# Вычисляем SSIM, ref.y4m — исходник той же продолжительности и того же разрешения.
!ffmpeg -i crf-60.webm -i ref.y4m -lavfi ssim=f=crf-60.log -f null -
!ffmpeg -i vbr-200k.webm -i ref.y4m -lavfi ssim=f=vbr-200k.log -f null -
# Достаём данные.
import re
crf = !cat crf-60.log
vbr = !vbr-200k.log
crf_x = vbr_x = range(1, 240)
crf_y = [float(re.search(r'\((.*?)\)', line).group(1)) for line in crf]
vbr_y = [float(re.search(r'\((.*?)\)', line).group(1)) for line in vbr]
# Строим график.
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(25,14))
ax = fig.add_subplot(111)
ax.set_xlim(1, 255)
ax.set_ylim(10, 22)
clr1 = (0.12156862745098039, 0.4666666666666667, 0.7058823529411765)
clr2 = (1.0, 0.4980392156862745, 0.054901960784313725)
ax.plot(crf_x, crf_y, lw=2, color=clr1)
ax.plot(vbr_x, vbr_y, lw=2, color=clr2)
ax.set_ylabel('SSIM', size=20)
ax.xaxis.set_tick_params(size=0)
ax.yaxis.set_tick_params(size=0)
fps = 24000/1001
ax.set_xticks([t*fps for t in range(1, 10)])
ax.set_xticklabels(['{:02d}:{:02d}:{:02d}'.format(t//3600, t%3600//60, t%60) for t in range(1, 10)], size=13)
ax.tick_params('y', labelsize=13)
ax.set_title('VBR vs CRF', size=25, y=1.01)
ax.grid('on')
ax.text(crf_x[-1] + 2, crf_y[-1] - 0.1, 'CRF', color=clr1, size=15)
ax.text(crf_x[-1] + 2, crf_y[-1] - 0.35, '15.955 avg', color=clr1, size=12)
ax.text(vbr_x[-1] + 2, vbr_y[-1] - 0.1, 'VBR', color=clr2, size=15)
ax.text(vbr_x[-1] + 2, vbr_y[-1] - 0.35, '15.269 avg', color=clr2, size=12)
fig.savefig('graph.png', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment