Separated ffmpy arguments into dicts. (use later to include covers)

This commit is contained in:
RealStickman 2022-10-08 14:15:24 +02:00
parent c14fc5a77d
commit b145688b6b

View File

@ -121,9 +121,11 @@ def loudness_info(inputfile) -> dict[str, str]:
def convert(inputfile, outputfile, loudness): def convert(inputfile, outputfile, loudness):
print("Working on ", os.path.basename(inputfile)) print("Working on ", os.path.basename(inputfile))
ff = ffmpy.FFmpeg( # coverpath = os.path.join(os.path.dirname(inputfile), "cover.jpg")
inputs={inputfile: None}, # NOTE including covers into ogg/opus containers currently doesn't work
outputs={ # https://trac.ffmpeg.org/ticket/4448
inputcmd = {inputfile: None}
outputcmd = {
outputfile: "-pass 2" outputfile: "-pass 2"
" " " "
"-filter:a" "-filter:a"
@ -131,8 +133,7 @@ def convert(inputfile, outputfile, loudness):
"loudnorm=I=-30.0:" "loudnorm=I=-30.0:"
"measured_I={input_i}:" "measured_I={input_i}:"
"measured_LRA={input_lra}:" "measured_LRA={input_lra}:"
"measured_tp={input_tp}:measured_thresh={input_thresh}:" "measured_tp={input_tp}:measured_thresh={input_thresh}"
"print_format=json"
" " " "
"-c:a libopus" "-c:a libopus"
" " " "
@ -142,10 +143,14 @@ def convert(inputfile, outputfile, loudness):
input_tp=loudness["input_tp"], input_tp=loudness["input_tp"],
input_thresh=loudness["input_thresh"], input_thresh=loudness["input_thresh"],
) )
}, }
ff = ffmpy.FFmpeg(
inputs=inputcmd,
outputs=outputcmd,
global_options=("-y", "-v error"), global_options=("-y", "-v error"),
) )
# print(ff.cmd) print(ff.cmd)
ff.run() ff.run()
@ -179,12 +184,15 @@ def main(inputfile: str):
# print(os.path.basename(inputfile)) # print(os.path.basename(inputfile))
# print(outputfile) # print(outputfile)
remove_picture(inputfile=inputfile) # remove_picture(inputfile=inputfile)
loudness = loudness_info(inputfile=inputfile) loudness = loudness_info(inputfile=inputfile)
convert(inputfile=inputfile, outputfile=outputfile, loudness=loudness) convert(inputfile=inputfile, outputfile=outputfile, loudness=loudness)
if __name__ == "__main__": if __name__ == "__main__":
# start time of program
starttime = time.time()
parser = argparse.ArgumentParser(description="") parser = argparse.ArgumentParser(description="")
# Input directory # Input directory
@ -251,4 +259,4 @@ if __name__ == "__main__":
# write this run's time into file # write this run's time into file
with open(timefile, "w") as file: with open(timefile, "w") as file:
file.write(str(time.time())) file.write(str(starttime))