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
|
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 __name__ == "__main__":
|
||||||
if not os.path.isdir("encoded"):
|
if not os.path.isdir("encoded"):
|
||||||
os.mkdir("encoded")
|
os.mkdir("encoded")
|
||||||
@ -198,6 +231,7 @@ if __name__ == "__main__":
|
|||||||
preset=preset,
|
preset=preset,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# execute previously defined encoding settings
|
||||||
starttime = now()
|
starttime = now()
|
||||||
ff.run()
|
ff.run()
|
||||||
endtime = now()
|
endtime = now()
|
||||||
@ -205,21 +239,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
outputfilesize = os.path.getsize(outputfile) / 1024 / 1024
|
outputfilesize = os.path.getsize(outputfile) / 1024 / 1024
|
||||||
|
|
||||||
ff = ffmpy.FFmpeg(
|
vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile)
|
||||||
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)
|
|
||||||
|
|
||||||
write_line(
|
write_line(
|
||||||
codec=codec,
|
codec=codec,
|
||||||
@ -228,8 +248,8 @@ if __name__ == "__main__":
|
|||||||
infile="Sparks_in_Blender.webm",
|
infile="Sparks_in_Blender.webm",
|
||||||
outfilesize=outputfilesize,
|
outfilesize=outputfilesize,
|
||||||
enctime=difftime,
|
enctime=difftime,
|
||||||
vmafmean=vmaf["pooled_metrics"]["vmaf"]["mean"],
|
vmafmean=vmaf["mean"],
|
||||||
vmafmin=vmaf["pooled_metrics"]["vmaf"]["min"],
|
vmafmin=vmaf["min"],
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(outputfile)
|
os.remove(outputfile)
|
||||||
|
Loading…
Reference in New Issue
Block a user