Compare commits
No commits in common. "e4baf3d28f87c64e003d7ee5c6638d870eeb1ab0" and "1f5036effe93b8bb713c9cf765fe9cd7adbf9ec1" have entirely different histories.
e4baf3d28f
...
1f5036effe
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
vmaf.json
|
||||
*.csv
|
||||
encoded/
|
||||
*.log
|
||||
|
@ -50,7 +50,7 @@ encoding: dict[str, Any] = {
|
||||
|
||||
# program version
|
||||
# make tests reproducible by tag
|
||||
version = "v0.0.1a3"
|
||||
version = "v0.0.1a2"
|
||||
|
||||
# always round timestamp to integer
|
||||
def now():
|
||||
@ -66,8 +66,6 @@ def write_line(
|
||||
enctime: int,
|
||||
vmafmean: float,
|
||||
vmafmin: float,
|
||||
ssim: float,
|
||||
mse: float,
|
||||
):
|
||||
"""
|
||||
Write line to data csv
|
||||
@ -81,8 +79,6 @@ def write_line(
|
||||
enctime (int): Time to encode
|
||||
vmafmean (float): Mean VMAF score
|
||||
vmafmin (float): Min VMAF score
|
||||
ssim (float): SSIM Score
|
||||
mse (float): MSE Score
|
||||
"""
|
||||
with open(datafile, "a", newline="") as file:
|
||||
write = csv.writer(file)
|
||||
@ -96,8 +92,6 @@ def write_line(
|
||||
enctime,
|
||||
vmafmean,
|
||||
vmafmin,
|
||||
ssim,
|
||||
mse,
|
||||
)
|
||||
)
|
||||
|
||||
@ -185,19 +179,25 @@ def score_vmaf(outputfile: str, inputfile: str) -> dict[str, float]:
|
||||
return vmaf
|
||||
|
||||
|
||||
def parse_kv_files(inputfile: str) -> list[dict[str, Any]]:
|
||||
# create list of dicts. Each dict is one line in the file
|
||||
lines: list[dict[str, Any]] = []
|
||||
# Steps to get mse value
|
||||
with open(inputfile) as file:
|
||||
for line in file:
|
||||
linelist = line.rstrip().split()
|
||||
# NOTE stripping the last item because ssim has values like this in the location: (26.088579)
|
||||
# For PSNR, psnr_v:87.80 is affected. (YUV color space). Not really a priority to fix atm
|
||||
linedict = dict(kv.split(":") for kv in linelist[:-1])
|
||||
lines.append(linedict)
|
||||
def score_psnr(outputfile: str, inputfile: str):
|
||||
"""
|
||||
Calculate a file's MSE (mean-square error) using PSNR. A lower value is better
|
||||
|
||||
return lines
|
||||
Parameters:
|
||||
outputfile (str): Path to output file
|
||||
inputfile (str): Path to input file
|
||||
|
||||
Return:
|
||||
TBD
|
||||
"""
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs=OrderedDict([(outputfile, None), (inputfile, None)]),
|
||||
outputs={"-": "-lavfi psnr=stats_file=psnr.log -f null"},
|
||||
)
|
||||
|
||||
ff.run()
|
||||
|
||||
# Steps to get mse value
|
||||
|
||||
|
||||
def score_ssim(outputfile: str, inputfile: str):
|
||||
@ -218,51 +218,7 @@ def score_ssim(outputfile: str, inputfile: str):
|
||||
|
||||
ff.run()
|
||||
|
||||
# get average ssim value
|
||||
ssim: list[dict[str, Any]] = parse_kv_files("ssim.log")
|
||||
|
||||
# add all ssim_avg values together
|
||||
ssim_tot: float = 0.0
|
||||
for i in ssim:
|
||||
ssim_tot += float(i["All"])
|
||||
|
||||
# get mse average
|
||||
ssim_avg: float = ssim_tot / len(ssim)
|
||||
|
||||
return ssim_avg
|
||||
|
||||
|
||||
def score_psnr(outputfile: str, inputfile: str) -> float:
|
||||
"""
|
||||
Calculate a file's MSE (mean-square error) using PSNR. A lower value is better
|
||||
|
||||
Parameters:
|
||||
outputfile (str): Path to output file
|
||||
inputfile (str): Path to input file
|
||||
|
||||
Return:
|
||||
TBD
|
||||
"""
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs=OrderedDict([(outputfile, None), (inputfile, None)]),
|
||||
outputs={"-": "-lavfi psnr=stats_file=psnr.log -f null"},
|
||||
# outputs={"-": "-filter_complex psnr=stats_file=psnr.log -f null"},
|
||||
)
|
||||
|
||||
ff.run()
|
||||
|
||||
# get average mse value
|
||||
psnr: list[dict[str, Any]] = parse_kv_files("psnr.log")
|
||||
|
||||
# add all mse_avg values together
|
||||
mse_tot: float = 0.0
|
||||
for i in psnr:
|
||||
mse_tot += float(i["mse_avg"])
|
||||
|
||||
# get mse average
|
||||
mse_avg: float = mse_tot / len(psnr)
|
||||
|
||||
return mse_avg
|
||||
# Steps to get ssim value
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -283,8 +239,6 @@ if __name__ == "__main__":
|
||||
"Encode time (s)",
|
||||
"VMAF Score (mean)",
|
||||
"VMAF Score (min)",
|
||||
"SSIM Score",
|
||||
"MSE Score",
|
||||
)
|
||||
)
|
||||
|
||||
@ -333,10 +287,6 @@ if __name__ == "__main__":
|
||||
|
||||
vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile)
|
||||
|
||||
ssim = score_ssim(outputfile=outputfile, inputfile=inputfile)
|
||||
|
||||
mse = score_psnr(outputfile=outputfile, inputfile=inputfile)
|
||||
|
||||
write_line(
|
||||
codec=codec,
|
||||
crf=crf,
|
||||
@ -346,8 +296,6 @@ if __name__ == "__main__":
|
||||
enctime=difftime,
|
||||
vmafmean=vmaf["mean"],
|
||||
vmafmin=vmaf["min"],
|
||||
ssim=ssim,
|
||||
mse=mse,
|
||||
)
|
||||
|
||||
os.remove(outputfile)
|
||||
|
Loading…
Reference in New Issue
Block a user