From c1063b4ff8472a4f12fdc401d835ee259dcb3283 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 27 Mar 2025 10:08:05 +0000 Subject: [PATCH] more things depend on gif. --- content/models.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/content/models.py b/content/models.py index 77a3133..1b98f49 100644 --- a/content/models.py +++ b/content/models.py @@ -200,26 +200,27 @@ class Content(models.Model): if self.photo and self.photo.image.url.endswith('.gif'): video_path = self.photo.image.path.replace('.gif', '.mp4') image_path = self.photo.image.path.replace('.gif', '.jpg') - if os.path.exists(self.photo.image.path) and not os.path.exists(video_path): - height = self.photo.image.height - if height % 2: - height += 1 - cmd = [ - 'ffmpeg', - '-hide_banner', '-nostats', '-loglevel', 'error', - '-i', self.photo.image.path, - '-vf', 'scale=-2:%s' % height, - '-pix_fmt', 'yuv420p', - video_path - ] - subprocess.call(cmd) - if not os.path.exists(image_path): - cmd = [ - 'ffmpeg', - '-hide_banner', '-nostats', '-loglevel', 'error', - '-i', self.photo.image.path, '-frames:v', '1', image_path - ] - subprocess.call(cmd) + if os.path.exists(self.photo.image.path): + if not os.path.exists(video_path): + height = self.photo.image.height + if height % 2: + height += 1 + cmd = [ + 'ffmpeg', + '-hide_banner', '-nostats', '-loglevel', 'error', + '-i', self.photo.image.path, + '-vf', 'scale=-2:%s' % height, + '-pix_fmt', 'yuv420p', + video_path + ] + subprocess.call(cmd) + if not os.path.exists(image_path): + cmd = [ + 'ffmpeg', + '-hide_banner', '-nostats', '-loglevel', 'error', + '-i', self.photo.image.path, '-frames:v', '1', image_path + ] + subprocess.call(cmd) return self.photo.image.url.replace('.gif', '.mp4') @cached_property