Restructuring to function both as cli and import
Some checks failed
ci/woodpecker/push/linting Pipeline failed
Some checks failed
ci/woodpecker/push/linting Pipeline failed
This commit is contained in:
parent
394c6d501c
commit
8584ff911e
@ -58,6 +58,7 @@ def now():
|
|||||||
|
|
||||||
|
|
||||||
def write_line(
|
def write_line(
|
||||||
|
datafile: str,
|
||||||
codec: str,
|
codec: str,
|
||||||
crf: int,
|
crf: int,
|
||||||
preset: Union[str, int],
|
preset: Union[str, int],
|
||||||
@ -73,6 +74,7 @@ def write_line(
|
|||||||
Write line to data csv
|
Write line to data csv
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
datafile (str): Path to output CSV filename
|
||||||
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
|
||||||
@ -241,7 +243,7 @@ def score_psnr(outputfile: str, inputfile: str) -> float:
|
|||||||
inputfile (str): Path to input file
|
inputfile (str): Path to input file
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
TBD
|
TODO
|
||||||
"""
|
"""
|
||||||
ff = ffmpy.FFmpeg(
|
ff = ffmpy.FFmpeg(
|
||||||
inputs=OrderedDict([(outputfile, None), (inputfile, None)]),
|
inputs=OrderedDict([(outputfile, None), (inputfile, None)]),
|
||||||
@ -265,12 +267,23 @@ def score_psnr(outputfile: str, inputfile: str) -> float:
|
|||||||
return mse_avg
|
return mse_avg
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main(inputfile: str, outputpath: str = "encodes"):
|
||||||
if not os.path.isdir("encodes"):
|
"""
|
||||||
os.mkdir("encodes")
|
Main program function so this program can be used from the command line or as a library import.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
inputfile (str): Path to input video file
|
||||||
|
|
||||||
|
Optional Parameters:
|
||||||
|
outputpath (str): Path to output folder. Defaults to "encodes" in the current working directory
|
||||||
|
"""
|
||||||
|
if not os.path.isdir(outputpath):
|
||||||
|
os.mkdir(outputpath)
|
||||||
|
|
||||||
datafile = version + "-data-" + str(now()) + ".csv"
|
datafile = version + "-data-" + str(now()) + ".csv"
|
||||||
|
|
||||||
|
inputfilename = os.path.basename(os.path.splitext(inputfile)[0])
|
||||||
|
|
||||||
with open(datafile, "w", newline="") as file:
|
with open(datafile, "w", newline="") as file:
|
||||||
write = csv.writer(file)
|
write = csv.writer(file)
|
||||||
write.writerow(
|
write.writerow(
|
||||||
@ -288,17 +301,15 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO expose this as variable/argument?
|
|
||||||
inputfile = "source/Sparks_in_Blender.webm"
|
|
||||||
|
|
||||||
for codec in encoding:
|
for codec in encoding:
|
||||||
for crf in encoding[codec]["crf"]:
|
for crf in encoding[codec]["crf"]:
|
||||||
for preset in encoding[codec]["presets"]:
|
for preset in encoding[codec]["presets"]:
|
||||||
# TODO selection of output location with arguments?
|
# TODO selection of output location with arguments?
|
||||||
outputfile = os.path.join(
|
outputfile = os.path.join(
|
||||||
"encodes",
|
outputpath,
|
||||||
(
|
(
|
||||||
"Sparks_in_Blender-codec_"
|
inputfilename
|
||||||
|
+ "-codec_"
|
||||||
+ codec
|
+ codec
|
||||||
+ "-crf_"
|
+ "-crf_"
|
||||||
+ str(crf)
|
+ str(crf)
|
||||||
@ -340,10 +351,11 @@ if __name__ == "__main__":
|
|||||||
mse = score_psnr(outputfile=outputfile, inputfile=inputfile)
|
mse = score_psnr(outputfile=outputfile, inputfile=inputfile)
|
||||||
|
|
||||||
write_line(
|
write_line(
|
||||||
|
datafile=datafile,
|
||||||
codec=codec,
|
codec=codec,
|
||||||
crf=crf,
|
crf=crf,
|
||||||
preset=preset,
|
preset=preset,
|
||||||
infile="Sparks_in_Blender.webm",
|
infile=os.path.basename(inputfile),
|
||||||
outfilesize=outputfilesize,
|
outfilesize=outputfilesize,
|
||||||
enctime=difftime,
|
enctime=difftime,
|
||||||
vmafmean=vmaf["mean"],
|
vmafmean=vmaf["mean"],
|
||||||
@ -358,3 +370,11 @@ if __name__ == "__main__":
|
|||||||
os.remove("vmaf.json")
|
os.remove("vmaf.json")
|
||||||
os.remove("ssim.log")
|
os.remove("ssim.log")
|
||||||
os.remove("psnr.log")
|
os.remove("psnr.log")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# TODO expose this as variable/argument?
|
||||||
|
outputpath: str = ""
|
||||||
|
inputfile: str = "source/Sparks_in_Blender.webm"
|
||||||
|
|
||||||
|
main(inputfile=inputfile)
|
||||||
|
Loading…
Reference in New Issue
Block a user