Fix lossless conversion bit depth issues (#616)

This commit is contained in:
disconnect78 2024-02-07 21:22:39 +00:00 committed by GitHub
parent b01382f267
commit 4353c84837
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 13 deletions

View File

@ -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])