Skip to content

Commit

Permalink
feat: add to_mp3 attribute in FFmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Feb 17, 2024
1 parent 8efb632 commit dc45c74
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions neonize/utils/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,28 @@ def call(self, cmd: List[str]):
)
return out

def to_mp3(self) -> bytes:
temp = tempfile.gettempdir() + "/" + time.time().__str__() + ".mp3"
self.call(
[
"ffmpeg",
"-i",
self.filepath,
"-vn",
"-ar",
"44100",
"-ac",
"2",
"-b:a",
"192k",
temp,
]
)
with open(temp, "rb") as file:
buf = file.read()
os.remove(temp)
return buf

def extract_thumbnail(
self,
format: ImageFormat = ImageFormat.JPG,
Expand Down

0 comments on commit dc45c74

Please sign in to comment.