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
|
vmaf.json
|
||||||
*.csv
|
*.csv
|
||||||
encoded/
|
encoded/
|
||||||
*.log
|
|
||||||
|
@ -50,7 +50,7 @@ encoding: dict[str, Any] = {
|
|||||||
|
|
||||||
# program version
|
# program version
|
||||||
# make tests reproducible by tag
|
# make tests reproducible by tag
|
||||||
version = "v0.0.1a3"
|
version = "v0.0.1a2"
|
||||||
|
|
||||||
# always round timestamp to integer
|
# always round timestamp to integer
|
||||||
def now():
|
def now():
|
||||||
@ -66,23 +66,19 @@ def write_line(
|
|||||||
enctime: int,
|
enctime: int,
|
||||||
vmafmean: float,
|
vmafmean: float,
|
||||||
vmafmin: float,
|
vmafmin: float,
|
||||||
ssim: float,
|
|
||||||
mse: float,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Write line to data csv
|
Write line to data csv
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
codec (str): Codec used
|
codec (str): Codec used
|
||||||
crf (int): CRF used
|
crf (int): CRF used
|
||||||
preset (str/int): Preset used
|
preset (str/int): Preset used
|
||||||
infile (str): Input file name
|
infile (str): Input file name
|
||||||
outfilesize (float): Size of output file
|
outfilesize (float): Size of output file
|
||||||
enctime (int): Time to encode
|
enctime (int): Time to encode
|
||||||
vmafmean (float): Mean VMAF score
|
vmafmean (float): Mean VMAF score
|
||||||
vmafmin (float): Min VMAF score
|
vmafmin (float): Min VMAF score
|
||||||
ssim (float): SSIM Score
|
|
||||||
mse (float): MSE Score
|
|
||||||
"""
|
"""
|
||||||
with open(datafile, "a", newline="") as file:
|
with open(datafile, "a", newline="") as file:
|
||||||
write = csv.writer(file)
|
write = csv.writer(file)
|
||||||
@ -96,8 +92,6 @@ def write_line(
|
|||||||
enctime,
|
enctime,
|
||||||
vmafmean,
|
vmafmean,
|
||||||
vmafmin,
|
vmafmin,
|
||||||
ssim,
|
|
||||||
mse,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -185,19 +179,25 @@ def score_vmaf(outputfile: str, inputfile: str) -> dict[str, float]:
|
|||||||
return vmaf
|
return vmaf
|
||||||
|
|
||||||
|
|
||||||
def parse_kv_files(inputfile: str) -> list[dict[str, Any]]:
|
def score_psnr(outputfile: str, inputfile: str):
|
||||||
# create list of dicts. Each dict is one line in the file
|
"""
|
||||||
lines: list[dict[str, Any]] = []
|
Calculate a file's MSE (mean-square error) using PSNR. A lower value is better
|
||||||
# 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)
|
|
||||||
|
|
||||||
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):
|
def score_ssim(outputfile: str, inputfile: str):
|
||||||
@ -218,51 +218,7 @@ def score_ssim(outputfile: str, inputfile: str):
|
|||||||
|
|
||||||
ff.run()
|
ff.run()
|
||||||
|
|
||||||
# get average ssim value
|
# Steps to get 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
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -283,8 +239,6 @@ if __name__ == "__main__":
|
|||||||
"Encode time (s)",
|
"Encode time (s)",
|
||||||
"VMAF Score (mean)",
|
"VMAF Score (mean)",
|
||||||
"VMAF Score (min)",
|
"VMAF Score (min)",
|
||||||
"SSIM Score",
|
|
||||||
"MSE Score",
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -333,10 +287,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile)
|
vmaf = score_vmaf(outputfile=outputfile, inputfile=inputfile)
|
||||||
|
|
||||||
ssim = score_ssim(outputfile=outputfile, inputfile=inputfile)
|
|
||||||
|
|
||||||
mse = score_psnr(outputfile=outputfile, inputfile=inputfile)
|
|
||||||
|
|
||||||
write_line(
|
write_line(
|
||||||
codec=codec,
|
codec=codec,
|
||||||
crf=crf,
|
crf=crf,
|
||||||
@ -346,8 +296,6 @@ if __name__ == "__main__":
|
|||||||
enctime=difftime,
|
enctime=difftime,
|
||||||
vmafmean=vmaf["mean"],
|
vmafmean=vmaf["mean"],
|
||||||
vmafmin=vmaf["min"],
|
vmafmin=vmaf["min"],
|
||||||
ssim=ssim,
|
|
||||||
mse=mse,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(outputfile)
|
os.remove(outputfile)
|
||||||
|
Loading…
Reference in New Issue
Block a user