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
@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
@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
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")
streams = info.get("streams", [])
hwaccel = True
maxrate = "5M"
for stream in streams:
self.log.info("Found stream: %s", stream.get("codec_name"))
if stream.get("codec_name") == "hevc":
@ -159,8 +162,12 @@ class AutoResponder(commands.Cog):
hwaccel = False
break
else:
self.log.info("No HEVC streams found in %s", uri)
return update_reaction()
if int(info["format"]["size"]) >= 25 * 1024 * 1024:
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
with tempfile.NamedTemporaryFile(suffix=extension) as tmp_dl:
self.log.info("Downloading %r to %r", uri, tmp_dl.name)
@ -195,10 +202,8 @@ class AutoResponder(commands.Cog):
tmp_dl.name,
"-c:v",
"libx264",
"-crf",
"25",
"-maxrate",
"5M",
maxrate,
"-minrate",
"100K",
"-bufsize",
@ -216,7 +221,7 @@ class AutoResponder(commands.Cog):
"-movflags",
"faststart",
"-profile:v",
"main",
"high",
"-y",
"-hide_banner",
]