From 36be58561b1a29ec51dc95bcd4d1d82893eba9ce Mon Sep 17 00:00:00 2001 From: Toks Date: Sun, 5 Oct 2014 13:16:27 -0400 Subject: [PATCH] Fix last frame of webms not displaying right in some browsers Some browsers like Chrome (and some video players like MPC-HC) do not display the last frame of a webm (or they display it, but only very briefly) if set to loop. This commit is a hack to force the last frame to display for the correct amount of time by duplicating it. --- app/logical/pixiv_ugoira_converter.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/logical/pixiv_ugoira_converter.rb b/app/logical/pixiv_ugoira_converter.rb index b7333a22b..bc964ed95 100644 --- a/app/logical/pixiv_ugoira_converter.rb +++ b/app/logical/pixiv_ugoira_converter.rb @@ -48,6 +48,15 @@ class PixivUgoiraConverter end end + # Duplicate last frame to avoid it being displayed only for a very short amount of time. + folder.to_a.last.name =~ /\A(\d{6})(\..+)\Z/ + new_last_index = $1.to_i + 1 + file_ext = $2 + new_last_filename = ("%06d" % new_last_index) + file_ext + path_from = File.join(tmpdir, "images", folder.to_a.last.name) + path_to = File.join(tmpdir, "images", new_last_filename) + FileUtils.cp(path_from, path_to) + delay_sum = 0 timecodes_path = File.join(tmpdir, "timecodes.tc") File.open(timecodes_path, "w+") do |f| @@ -57,6 +66,7 @@ class PixivUgoiraConverter delay_sum += img["delay"] end f.write("#{delay_sum}\n") + f.write("#{delay_sum}\n") end ext = folder.first.name.match(/\.(.+)$/)[1]