remove ffmpy deps from compression
This commit is contained in:
parent
c3dbdefc3f
commit
b1d89075d3
@ -1,16 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
from ffmpy import FFmpeg
|
||||
|
||||
class FFmpeg:
|
||||
input: str
|
||||
output: str
|
||||
format: str
|
||||
bitrate: str | None
|
||||
freq: int | None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input="pipe:0",
|
||||
output="pipe:1",
|
||||
format="mp3",
|
||||
bitrate=None,
|
||||
freq=None,
|
||||
):
|
||||
self.input = input
|
||||
self.output = output
|
||||
self.format = format
|
||||
self.bitrate = bitrate
|
||||
self.freq = freq
|
||||
|
||||
def __get_cmd(self) -> list[str]:
|
||||
cmd = ["ffmpeg", "-i", self.input, "-f", self.format, self.output]
|
||||
|
||||
if self.bitrate is not None:
|
||||
cmd += ["-b:a", self.bitrate]
|
||||
if self.freq is not None:
|
||||
cmd += ["-ar", str(self.freq)]
|
||||
return cmd
|
||||
|
||||
def run(self):
|
||||
cmd = self.__get_cmd()
|
||||
|
||||
subprocess.Popen(cmd)
|
||||
|
||||
|
||||
def main():
|
||||
ff = FFmpeg(
|
||||
inputs={"pipe:0": None},
|
||||
outputs={"pipe:1": "-ar 8000 -b:a 128k -f mp3"},
|
||||
)
|
||||
ff.run(input_data=sys.stdin.buffer.read())
|
||||
ff = FFmpeg(bitrate="128k", freq=8000)
|
||||
ff.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1 +0,0 @@
|
||||
ffmpy~=0.3
|
Reference in New Issue
Block a user