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.
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user