From 4353c848379197dd49a18d36d8814c003bbe1191 Mon Sep 17 00:00:00 2001 From: disconnect78 <50294879+disconnect78@users.noreply.github.com> Date: Wed, 7 Feb 2024 21:22:39 +0000 Subject: [PATCH] Fix lossless conversion bit depth issues (#616) --- streamrip/converter.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/streamrip/converter.py b/streamrip/converter.py index 6668cda..29efd16 100644 --- a/streamrip/converter.py +++ b/streamrip/converter.py @@ -121,27 +121,31 @@ class Converter: command.extend(self.ffmpeg_arg.split()) if self.lossless: - if isinstance(self.sampling_rate, int): - sampling_rates = "|".join( - str(rate) for rate in SAMPLING_RATES if rate <= self.sampling_rate - ) - command.extend(["-af", f"aformat=sample_rates={sampling_rates}"]) + aformat = [] + if isinstance(self.sampling_rate, int): + sample_rates = "|".join(str(rate) for rate in SAMPLING_RATES if rate <= self.sampling_rate) + aformat.append(f"sample_rates={sample_rates}") elif self.sampling_rate is not None: - raise TypeError( - f"Sampling rate must be int, not {type(self.sampling_rate)}", - ) + raise TypeError(f"Sampling rate must be int, not {type(self.sampling_rate)}") if isinstance(self.bit_depth, int): - if int(self.bit_depth) == 16: - command.extend(["-sample_fmt", "s16"]) - elif int(self.bit_depth) in (24, 32): - command.extend(["-sample_fmt", "s32p"]) - else: + bit_depths = ["s16p", "s16"] + + if self.bit_depth in (24, 32): + bit_depths.extend(["s32p", "s32"]) + elif self.bit_depth != 16: raise ValueError("Bit depth must be 16, 24, or 32") + + sample_fmts = "|".join(bit_depths) + aformat.append(f"sample_fmts={sample_fmts}") elif self.bit_depth is not None: raise TypeError(f"Bit depth must be int, not {type(self.bit_depth)}") + if aformat: + aformat_params = ':'.join(aformat) + command.extend(["-af", f"aformat={aformat_params}"]) + # automatically overwrite command.extend(["-y", self.tempfile])