Handle metadata copying for opus files

This commit is contained in:
exu 2024-05-10 19:20:54 +02:00
parent c50b87fb7c
commit 08fd5bc592

View File

@ -128,7 +128,15 @@ 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}
# 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"} 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"))