Enable better compression for auto-transcoding

This commit is contained in:
Nexus 2024-07-10 23:20:24 +01:00
parent 00b80a929c
commit 608dd46afa

View file

@ -68,11 +68,13 @@ class AutoResponder(commands.Cog):
@staticmethod @staticmethod
@typing.overload @typing.overload
def extract_links(text: str, *domains: str, raw: typing.Literal[True] = False) -> list[ParseResult]: ... def extract_links(text: str, *domains: str, raw: typing.Literal[True] = False) -> list[ParseResult]:
...
@staticmethod @staticmethod
@typing.overload @typing.overload
def extract_links(text: str, *domains: str, raw: typing.Literal[False] = False) -> list[str]: ... def extract_links(text: str, *domains: str, raw: typing.Literal[False] = False) -> list[str]:
...
@staticmethod @staticmethod
def extract_links(text: str, *domains: str, raw: bool = False) -> list[str | ParseResult]: def extract_links(text: str, *domains: str, raw: bool = False) -> list[str | ParseResult]:
@ -147,6 +149,7 @@ class AutoResponder(commands.Cog):
return update_reaction("\N{TIMER CLOCK}\U0000fe0f") return update_reaction("\N{TIMER CLOCK}\U0000fe0f")
streams = info.get("streams", []) streams = info.get("streams", [])
hwaccel = True hwaccel = True
maxrate = "5M"
for stream in streams: for stream in streams:
self.log.info("Found stream: %s", stream.get("codec_name")) self.log.info("Found stream: %s", stream.get("codec_name"))
if stream.get("codec_name") == "hevc": if stream.get("codec_name") == "hevc":
@ -159,8 +162,12 @@ class AutoResponder(commands.Cog):
hwaccel = False hwaccel = False
break break
else: else:
self.log.info("No HEVC streams found in %s", uri) if int(info["format"]["size"]) >= 25 * 1024 * 1024:
return update_reaction() self.log.warning("%s is too large to render in discord, compressing", uri)
maxrate = "1M"
else:
self.log.info("No HEVC streams found in %s", uri)
return update_reaction()
extension = pathlib.Path(uri).suffix extension = pathlib.Path(uri).suffix
with tempfile.NamedTemporaryFile(suffix=extension) as tmp_dl: with tempfile.NamedTemporaryFile(suffix=extension) as tmp_dl:
self.log.info("Downloading %r to %r", uri, tmp_dl.name) self.log.info("Downloading %r to %r", uri, tmp_dl.name)
@ -195,10 +202,8 @@ class AutoResponder(commands.Cog):
tmp_dl.name, tmp_dl.name,
"-c:v", "-c:v",
"libx264", "libx264",
"-crf",
"25",
"-maxrate", "-maxrate",
"5M", maxrate,
"-minrate", "-minrate",
"100K", "100K",
"-bufsize", "-bufsize",
@ -216,7 +221,7 @@ class AutoResponder(commands.Cog):
"-movflags", "-movflags",
"faststart", "faststart",
"-profile:v", "-profile:v",
"main", "high",
"-y", "-y",
"-hide_banner", "-hide_banner",
] ]