add amr compression

This commit is contained in:
ange 2024-07-01 18:45:15 +02:00
parent c9d670e717
commit f8cdf67560
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
2 changed files with 25 additions and 11 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
### Audio ### ### Audio ###
*.aif *.aif
*.amr
*.flac *.flac
*.iff *.iff
*.m3u *.m3u

View File

@ -7,31 +7,44 @@ class FFmpeg:
input: str input: str
output: str output: str
format: str format: str
bitrate: str | None bitrate: int | None
freq: int | None fpass: tuple[int, int] | None
def __init__( def __init__(
self, self,
input="pipe:0", input="pipe:0",
output="pipe:1", output="pipe:1",
format="mp3", format="amr",
bitrate=None, bitrate=None,
freq=None, fpass=None,
): ):
self.input = input self.input = input
self.output = output self.output = output
self.format = format self.format = format
self.bitrate = bitrate self.bitrate = bitrate
self.freq = freq self.fpass = fpass
def __get_cmd(self) -> list[str]: def __get_cmd(self) -> list[str]:
cmd = ["ffmpeg", "-i", self.input, "-f", self.format, self.output] cmd = [
"ffmpeg",
"-i",
self.input,
"-f",
self.format,
"-ac",
"1",
"-ar",
"8000",
]
if self.bitrate is not None: if self.bitrate is not None:
cmd += ["-b:a", self.bitrate] cmd += ["-b:a", str(self.bitrate)]
if self.freq is not None: if self.fpass:
cmd += ["-ar", str(self.freq)] cmd += [
return cmd "-filter:a",
f"highpass=f={self.fpass[0]},lowpass=f={self.fpass[1]}",
]
return cmd + [self.output]
def run(self): def run(self):
cmd = self.__get_cmd() cmd = self.__get_cmd()
@ -40,7 +53,7 @@ class FFmpeg:
def main(): def main():
ff = FFmpeg(bitrate="128k", freq=8000) ff = FFmpeg(bitrate=12200, fpass=[200, 3400])
ff.run() ff.run()