diff --git a/Sparks_in_Blender_encode.py b/Sparks_in_Blender_encode.py index 6689a0d..95def85 100755 --- a/Sparks_in_Blender_encode.py +++ b/Sparks_in_Blender_encode.py @@ -94,6 +94,54 @@ def write_line( ) +def encode_general(inputfile: str, outputfile: str, codec: str, crf: str, preset: str): + """ + General encoding function + + Parameters: + inputfile (str): Path to input file + outputfile (str): Path to output file + codec (str): Codec used + crf (str): CRF value + preset (str): Choosen preset + """ + ff = ffmpy.FFmpeg( + inputs={inputfile: None}, + outputs={ + outputfile: "-c:v {videocodec} -crf {crf} -preset {preset} -g 240 -map 0:v:0 ".format( + videocodec=codec, + crf=crf, + preset=preset, + ) + }, + ) + + return ff + + +def encode_libaom(inputfile: str, outputfile: str, crf: str, preset: str): + """ + Encoding with libaom + + Parameters: + inputfile (str): Path to input file + outputfile (str): Path to output file + crf (str): CRF value + preset (str): Choosen preset + """ + ff = ffmpy.FFmpeg( + inputs={inputfile: None}, + outputs={ + outputfile: "-c:v libaom-av1 -crf {crf} -b:v 0 -cpu-used {preset} -row-mt 1 -tiles 2x2 -g 240 -map 0:v:0 ".format( + crf=crf, + preset=preset, + ) + }, + ) + + return ff + + if __name__ == "__main__": if not os.path.isdir("encoded"): os.mkdir("encoded") @@ -115,6 +163,8 @@ if __name__ == "__main__": ) ) + inputfile = "Sparks_in_Blender.webm" + for codec in encoding: for crf in encoding[codec]["crf"]: for preset in encoding[codec]["presets"]: @@ -133,26 +183,19 @@ if __name__ == "__main__": # libaom needs additional options if codec == "libaom-av1": - ff = ffmpy.FFmpeg( - inputs={"Sparks_in_Blender.webm": None}, - outputs={ - outputfile: "-c:v {videocodec} -crf {crf} -b:v 0 -cpu-used {preset} -row-mt 1 -tiles 2x2 -g 240 -map 0:v:0 ".format( - videocodec=codec, - crf=crf, - preset=preset, - ) - }, + ff = encode_libaom( + inputfile=inputfile, + outputfile=outputfile, + crf=crf, + preset=preset, ) else: - ff = ffmpy.FFmpeg( - inputs={"Sparks_in_Blender.webm": None}, - outputs={ - outputfile: "-c:v {videocodec} -crf {crf} -preset {preset} -g 240 -map 0:v:0 ".format( - videocodec=codec, - crf=crf, - preset=preset, - ) - }, + ff = encode_general( + inputfile=inputfile, + outputfile=outputfile, + codec=codec, + crf=crf, + preset=preset, ) starttime = now() @@ -162,7 +205,7 @@ if __name__ == "__main__": outputfilesize = os.path.getsize(outputfile) / 1024 / 1024 - ffvmaf = ffmpy.FFmpeg( + ff = ffmpy.FFmpeg( inputs=OrderedDict( [(outputfile, None), ("Sparks_in_Blender.webm", None)] ), @@ -173,7 +216,7 @@ if __name__ == "__main__": }, ) - ffvmaf.run() + ff.run() with open("vmaf.json", "r") as file: vmaf = json.load(file)