可视化ffmpeg基准 [英] Visualizing ffmpeg benchmarks
问题描述
我已经生成了基准,用于比较使用ffmpeg工具缩小视频文件(mp4)所采用的两种方法.
I have generated benchmarks for comparing two approaches taken for scaling down video files (mp4) using ffmpeg tool.
基准测试以以下格式记录:
The benchmarks are logged in this format :
x.mp4 Output_Resolution : 360p
Method : A
real 0m26.817s
user 1m38.058s
sys 0m0.504s
Method : B, some-parameter-for-B : b1
real 0m26.465s
user 1m42.824s
sys 0m1.111s
Method : B, some-parameter-for-B : b2
real 0m26.236s
user 1m42.194s
sys 0m0.862s
Method : B, some-parameter-for-B : b3
real 0m25.050s
user 1m36.492s
sys 0m0.680s
y.mp4 Output_Resolution : 144p
Method : A
real 1m9.426s
user 3m38.823s
sys 0m1.353s
Method : B, some-parameter-for-B : b1
real 1m4.956s
user 4m13.764s
sys 0m2.875s
Method : B, some-parameter-for-B : b2
real 1m5.033s
user 4m13.455s
sys 0m2.183s
Method : B, some-parameter-for-B : b3
real 0m25.050s
user 1m36.492s
sys 0m0.680s
我正在为多个视频文件和多个分辨率执行此操作.假设我需要使用下面的条形图来可视化给定分辨率的方法A和方法B的基准(实时)比较:
I am doing this for multiple video files and multiple resolutions. Lets say I need to visualize the comparison of benchmarks(real time) of method A and method B for given a resolution using bar chart below :
如何有效地从日志中获取必要的值,并在python中使用matplotlib对其进行绘制?
How do I efficiently get the necessary values from the the log and plot them using matplotlib in python ?
(我对解决该问题的方法更感兴趣)
推荐答案
我的方法将是这样
import matplotlib.pyplot as plt
import itertools
import numpy as np
def gettime(s):
e = ["".join(x) for _, x in itertools.groupby(s, key=str.isdigit)]
h = float(e[e.index("h") - 1]) if "h" in e else 0.0
m = float(e[e.index("m") - 1]) if "m" in e else 0.0
s = float(''.join(e[e.index("s") - 3:e.index("s")])) if "s" in e else 0.0
return 3600 * h + 60 * m + s
lines = []
with open("log.txt") as fp:
lines = fp.read().splitlines()
files = []
idx = 0
keys = ["A", "b1", "b2", "b3"]
methods = []
while idx < len(lines):
if ".mp4" in lines[idx]:
method = {k : 0.0 for k in keys}
files.append(lines[idx].split(' ')[0])
idx += 1
while idx < len(lines) and ".mp4" not in lines[idx]:
if "Method" in lines[idx]:
substrings = list(filter(None, lines[idx].split(' ')))
if substrings[-1] in keys:
while "real" not in lines[idx]:
idx += 1
method[substrings[-1]] = gettime(lines[idx].split(' ')[-1])
idx += 1
methods.append(method)
else:
idx += 1
data = np.zeros((len(keys), len(files)))
for idx, (d, f) in enumerate(zip(methods, files)):
data[:,idx] = np.array([d[k] for k in keys]).reshape(data[:,idx].shape)
x = np.arange(len(files))
w = (1.0 / data.shape[0]) * 0.6
names = ["A", "B, b1", "B, b2", "B, b3"]
for i in range(data.shape[0]):
plt.bar(x - w * i, data[i,:], width=w, label=names[i])
plt.tick_params(bottom = False)
plt.xticks(x - w * (i - 1.5), files)
plt.legend(title="Method")
plt.show()
基本思想:通过非常典型的解析从日志中提取时间,将它们存储到每个文件的字典中,然后填充一个数组并绘制其切片.这样做的方法比较简单,无需记账,但是我发现这样做可以使跟踪事情变得更加容易.
Basic idea: extract the times from the log via pretty typical parsing, store them into a dictionary for each file and then populate an array and plot slices of it. There are simpler ways to do this, with much less bookkeeping, but I find that it tends to make it easier to keep track of things.
问题中带有日志文件的结果是
The result with the log file in the question is
这篇关于可视化ffmpeg基准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!