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 ###
*.aif
*.amr
*.flac
*.iff
*.m3u

View File

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