posts: fix calculation of animated PNG duration.
Fix certain animated PNGs returning NaN as the duration because the frame rate was being reported as "0/0" by FFMpeg. This happens when the animation has zero delay between frames. This is supposed to mean a PNG with an infinitely fast frame rate, but in practice browsers limit it to around 10FPS. The exact frame rate browsers will use is unknown and implementation defined.
This commit is contained in:
@@ -59,10 +59,18 @@ class FFmpeg
|
||||
end
|
||||
end
|
||||
|
||||
# @return [Float, nil] The frame rate of the video or animation, or nil if
|
||||
# unknown. The frame rate can be unknown for animated PNGs that have zero
|
||||
# delay between frames.
|
||||
def frame_rate
|
||||
rate = video_streams.first[:avg_frame_rate] # "100/57"
|
||||
numerator, denominator = rate.split("/")
|
||||
(numerator.to_f / denominator.to_f)
|
||||
|
||||
if numerator.to_f == 0 || denominator.to_f == 0
|
||||
nil
|
||||
else
|
||||
(numerator.to_f / denominator.to_f)
|
||||
end
|
||||
end
|
||||
|
||||
def video_streams
|
||||
|
||||
Reference in New Issue
Block a user