From 51518e8f021be7ba883bfc96eee8ace0f1030999 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 27 May 2020 12:31:31 -0400 Subject: [PATCH] stackoverflow lied to me --- lib/philomena/processors/webm.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/philomena/processors/webm.ex b/lib/philomena/processors/webm.ex index 663db48a..29c446d5 100644 --- a/lib/philomena/processors/webm.ex +++ b/lib/philomena/processors/webm.ex @@ -136,11 +136,11 @@ defmodule Philomena.Processors.Webm do {webm, mp4} end - defp scale_gif(file, palette, _duration, {width, height}) do + defp scale_gif(file, palette, duration, {width, height}) do gif = Briefly.create!(extname: ".gif") scale_filter = "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease" palette_filter = "paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" - rate_filter = "setpts=N/TB/2" + rate_filter = rate_filter(duration) filter_graph = "[0:v]#{scale_filter},#{rate_filter}[x];[x][1:v]#{palette_filter}" {_output, 0} = @@ -189,4 +189,8 @@ defmodule Philomena.Processors.Webm do {new_width, new_height} end + + # Avoid division by zero + def rate_filter(duration) when duration > 0.5, do: "fps=1/#{duration / 10},settb=1/2,setpts=N" + def rate_filter(duration), do: "setpts=N/TB/2" end