From 7cfb390e05b318ce56245f8b5ef4565e6ef5a6fb Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 2 May 2020 02:12:54 -0400 Subject: [PATCH] add workaround for broken gif seeking in ffmpeg --- lib/philomena/processors/gif.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/philomena/processors/gif.ex b/lib/philomena/processors/gif.ex index 11b5a5ad..84c232fd 100644 --- a/lib/philomena/processors/gif.ex +++ b/lib/philomena/processors/gif.ex @@ -35,8 +35,12 @@ defmodule Philomena.Processors.Gif do end defp preview(duration, file) do + h264_equiv = Briefly.create!(extname: ".mp4") preview = Briefly.create!(extname: ".png") + # Hack workaround for broken FFmpeg behavior which + # cannot correctly seek in GIF image files + {_output, 0} = System.cmd("ffmpeg", [ "-loglevel", @@ -44,6 +48,18 @@ defmodule Philomena.Processors.Gif do "-y", "-i", file, + "-c:v", + "libx264", + h264_equiv + ]) + + {_output, 0} = + System.cmd("ffmpeg", [ + "-loglevel", + "0", + "-y", + "-i", + h264_equiv, "-ss", to_string(duration / 2), "-frames:v",