server/images: use ruffle exporter for swf thumbnails

Works with far more SWFs than ffmpeg. Using OpenGL backend.
This commit is contained in:
Eva 2023-05-19 12:10:04 +02:00
parent 782f069031
commit b34d38bfac

View file

@ -28,6 +28,9 @@ class Image:
def __init__(self, content: bytes) -> None: def __init__(self, content: bytes) -> None:
self.content = content self.content = content
self._reload_info() self._reload_info()
if self.info["format"]["format_name"] == "swf":
self.content = self.swf_to_png()
self._reload_info()
@property @property
def width(self) -> int: def width(self) -> int:
@ -60,10 +63,7 @@ class Image:
"png", "png",
"-", "-",
] ]
if ( if "duration" in self.info["format"]:
"duration" in self.info["format"]
and self.info["format"]["format_name"] != "swf"
):
duration = float(self.info["format"]["duration"]) duration = float(self.info["format"]["duration"])
if duration > 3: if duration > 3:
cli = [ cli = [
@ -76,6 +76,19 @@ class Image:
self.content = content self.content = content
self._reload_info() self._reload_info()
def swf_to_png(self) -> bytes:
return self._execute(
[
"--silent",
"-g",
"gl",
"--",
"{path}",
"-",
],
program="exporter",
)
def to_png(self) -> bytes: def to_png(self) -> bytes:
return self._execute( return self._execute(
[ [
@ -315,7 +328,7 @@ class Image:
) )
assert "format" in self.info assert "format" in self.info
assert "streams" in self.info assert "streams" in self.info
if len(self.info["streams"]) < 1: if len(self.info["streams"]) < 1 and self.info["format"]["format_name"] != "swf":
logger.warning("The video contains no video streams.") logger.warning("The video contains no video streams.")
raise errors.ProcessingError( raise errors.ProcessingError(
"The video contains no video streams." "The video contains no video streams."