ensure_valid_in(fileIn: AudioFile, supports_pipe: Literal[True] = ..., preprocess: Preprocessor | Sequence[Preprocessor] | None = None, valid_type: ValidInputType = ValidInputType.FLAC, caller: Any = None) -> AudioFile | subprocess.Popen
ensure_valid_in(fileIn: AudioFile, supports_pipe: Literal[False] = ..., preprocess: Preprocessor | Sequence[Preprocessor] | None = None, valid_type: ValidInputType = ValidInputType.FLAC, caller: Any = None) -> AudioFile
Ensures valid input for any encoder that accepts flac (all of them).
Passes existing file if no need to dither and is either wav or flac.
Source code in
muxtools/audio/audioutils.py
| def ensure_valid_in(
fileIn: AudioFile,
supports_pipe: bool = True,
preprocess: Preprocessor | Sequence[Preprocessor] | None = None,
valid_type: ValidInputType = ValidInputType.FLAC,
caller: Any = None,
) -> AudioFile | subprocess.Popen:
"""
Ensures valid input for any encoder that accepts flac (all of them).
Passes existing file if no need to dither and is either wav or flac.
"""
if fileIn.has_multiple_tracks(caller):
msg = f"'{fileIn.file.name}' is a container with multiple tracks.\n"
msg += f"The first audio track will be {'piped' if supports_pipe else 'extracted'} using default ffmpeg."
warn(msg, caller, 5)
trackinfo = fileIn.get_trackinfo()
container = fileIn.get_containerinfo()
preprocess = sanitize_pre(preprocess)
form = trackinfo.get_audio_format()
if form:
if form.is_lossy:
danger(f"It's strongly recommended to not reencode lossy audio! ({trackinfo.codec_name})", caller, 5)
elif form.should_not_transcode():
warn("Encoding tracks with special DTS Features or Atmos is very much discouraged.", caller, 5)
wont_process = not any([p.can_run(trackinfo, preprocess) for p in preprocess])
if (form == AudioFormat.PCM and container.format_name.lower() == "wav") and wont_process:
return fileIn
if valid_type.allows_flac():
valid_type = valid_type.remove_flac()
if (form == AudioFormat.FLAC and container.format_name.lower() == "flac") and wont_process:
return fileIn
if valid_type == ValidInputType.FLAC:
from .encoders import FF_FLAC
if supports_pipe:
return FF_FLAC(preprocess=preprocess).get_pipe(fileIn)
else:
return FF_FLAC(compression_level=0, preprocess=preprocess, output=os.path.join(get_temp_workdir(), "tempflac")).encode_audio(
fileIn, temp=True
)
else:
return get_pcm(fileIn, trackinfo, supports_pipe, preprocess, valid_type, caller)
|