VMAF score in function
This commit is contained in:
parent
f07ccc0efd
commit
4436528512
@ -142,6 +142,39 @@ def encode_libaom(inputfile: str, outputfile: str, crf: str, preset: str):
|
||||
return ff
|
||||
|
||||
|
||||
def score_vmaf(outputfile: str, inputfile: str) -> dict[str, float]:
|
||||
"""
|
||||
Calculate a file's VMAF score
|
||||
|
||||
Parameters:
|
||||
outputfile (str): Path to output file
|
||||
inputfile (str): Path to input file
|
||||
|
||||
Return:
|
||||
dict[str, float]: VMAF mean and min value
|
||||
"""
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs=OrderedDict([(outputfile, None), (inputfile, None)]),
|
||||
outputs={
|
||||
"-": "-filter_complex libvmaf=log_fmt=json:n_threads={cputhreads}:log_path=vmaf.json -f null".format(
|
||||
cputhreads=cpu_count()
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
ff.run()
|
||||
|
||||
with open("vmaf.json", "r") as file:
|
||||
vmafall = json.load(file)
|
||||
|
||||
vmaf: dict[str, float] = {
|
||||
"mean": vmafall["pooled_metrics"]["vmaf"]["mean"],
|
||||
"min": vmafall["pooled_metrics"]["vmaf"]["min"],
|
||||
}
|
||||
|
||||
return vmaf
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not os.path.isdir("encoded"):
|
||||
os.mkdir("encoded")
|
||||
@ -198,6 +231,7 @@ if __name__ == "__main__":
|
||||
preset=preset,
|
||||
)
|
||||
|
||||
# execute previously defined encoding settings
|
||||
starttime = now()
|
||||
ff.run()
|
||||
endtime = now()
|
||||
@ -205,21 +239,7 @@ if __name__ == "__main__":
|
||||
|
||||
outputfilesize = os.path.getsize(outputfile) / 1024 / 1024
|
||||
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs=OrderedDict(
|
||||
[(outputfile, None), ("Sparks_in_Blender.webm", None)]
|
||||
),
|
||||
outputs={
|
||||
"-": "-filter_complex libvmaf=log_fmt=json:n_threads={cputhreads}:log_path=vmaf.json -f null".format(
|
||||
cputhreads=cpu_count()
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
ff.run()
|
||||
|
||||
with open("vmaf.json", "r") as file:
|
||||
vmaf = json.load(file)
|
||||
vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile)
|
||||
|
||||
write_line(
|
||||
codec=codec,
|
||||
@ -228,8 +248,8 @@ if __name__ == "__main__":
|
||||
infile="Sparks_in_Blender.webm",
|
||||
outfilesize=outputfilesize,
|
||||
enctime=difftime,
|
||||
vmafmean=vmaf["pooled_metrics"]["vmaf"]["mean"],
|
||||
vmafmin=vmaf["pooled_metrics"]["vmaf"]["min"],
|
||||
vmafmean=vmaf["mean"],
|
||||
vmafmin=vmaf["min"],
|
||||
)
|
||||
|
||||
os.remove(outputfile)
|
||||
|
Loading…
Reference in New Issue
Block a user