From b34d38bfac6cd09e90da47c9d4ba01743c6a38f8 Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 19 May 2023 12:10:04 +0200 Subject: [PATCH] server/images: use ruffle exporter for swf thumbnails Works with far more SWFs than ffmpeg. Using OpenGL backend. --- server/szurubooru/func/images.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index e135d182..602f3bd0 100644 --- a/server/szurubooru/func/images.py +++ b/server/szurubooru/func/images.py @@ -28,6 +28,9 @@ class Image: def __init__(self, content: bytes) -> None: self.content = content self._reload_info() + if self.info["format"]["format_name"] == "swf": + self.content = self.swf_to_png() + self._reload_info() @property def width(self) -> int: @@ -60,10 +63,7 @@ class Image: "png", "-", ] - if ( - "duration" in self.info["format"] - and self.info["format"]["format_name"] != "swf" - ): + if "duration" in self.info["format"]: duration = float(self.info["format"]["duration"]) if duration > 3: cli = [ @@ -76,6 +76,19 @@ class Image: self.content = content self._reload_info() + def swf_to_png(self) -> bytes: + return self._execute( + [ + "--silent", + "-g", + "gl", + "--", + "{path}", + "-", + ], + program="exporter", + ) + def to_png(self) -> bytes: return self._execute( [ @@ -315,7 +328,7 @@ class Image: ) assert "format" 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.") raise errors.ProcessingError( "The video contains no video streams."