File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55import asyncio
6+ import contextlib
67from dataclasses import dataclass
78from datetime import date , datetime , time
89from http import HTTPStatus
@@ -344,6 +345,8 @@ async def transcode_file(
344345 Base Media format). Most likely this can be solved in better ways, but this will do for now.
345346 If the audio is served to clients in the original container (version 5 as of now), they will
346347 be very confused about the total duration of the file, for some reason...
348+ We also remove any metadata from the file prior to transcoding, mainly to avoid issues with
349+ badly encoded Unicode data in there.
347350
348351 Args:
349352 input_file (PathLike | str): The path to the audio file.
@@ -359,10 +362,29 @@ async def transcode_file(
359362
360363 if output_file is None : # pragma: no cover
361364 output_file = input_file .with_stem (f"{ input_file .stem } _out" )
365+ output_interim_file = input_file .with_stem (f"{ input_file .stem } _interim" )
362366
363367 transcode_options = transcode_options or {}
364368
365369 try :
370+ _LOGGER .debug ("Clearing metadata from file: %s" , input_file .name )
371+ with contextlib .suppress (UnicodeDecodeError ):
372+ await (
373+ FFmpeg ()
374+ .input (input_file )
375+ .output (
376+ output_interim_file ,
377+ {
378+ "map_metadata" : "-1" ,
379+ "c" : "copy" ,
380+ },
381+ )
382+ .execute ()
383+ )
384+
385+ input_file .unlink ()
386+ output_interim_file .rename (input_file )
387+
366388 ffprobe = FFmpeg (executable = "ffprobe" ).input (
367389 input_file ,
368390 print_format = "json" ,
You can’t perform that action at this time.
0 commit comments