Compare commits

..

2 Commits

Author SHA1 Message Date
exu
89b618a502 Change target loudness 2024-05-10 19:21:03 +02:00
exu
08fd5bc592 Handle metadata copying for opus files 2024-05-10 19:20:54 +02:00

View File

@ -61,7 +61,7 @@ def loudnorm(inputfile: str, outputfile: str):
# normalize audio # normalize audio
file_normalized = pyloudnorm.normalize.loudness( file_normalized = pyloudnorm.normalize.loudness(
data=data, input_loudness=loudness, target_loudness=-30.0 data=data, input_loudness=loudness, target_loudness=-18.0
) )
# write normalized audio to file # write normalized audio to file
@ -128,8 +128,16 @@ def ffmpeg_copy_metadata(inputfile: str, outputfile: str):
with tempfile.NamedTemporaryFile() as temp_audio: with tempfile.NamedTemporaryFile() as temp_audio:
shutil.copyfile(outputfile, temp_audio.name) shutil.copyfile(outputfile, temp_audio.name)
# get input file extension
extension = os.path.splitext(os.path.basename(inputfile))[1]
inputcmd = {inputfile: None, temp_audio.name: None} inputcmd = {inputfile: None, temp_audio.name: None}
outputcmd = {outputfile: "-map 1 -c copy -map_metadata 0"}
# NOTE opus maps metadata to the first audio stream. Other formats like flac, mp3 and m4a/aac by contrast map it to the input directly
if extension == ".opus":
outputcmd = {outputfile: "-map 1 -c copy -map_metadata 0:s"}
else:
outputcmd = {outputfile: "-map 1 -c copy -map_metadata 0"}
ff = ffmpy.FFmpeg(inputs=inputcmd, outputs=outputcmd, global_options=("-y")) ff = ffmpy.FFmpeg(inputs=inputcmd, outputs=outputcmd, global_options=("-y"))