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:
@@ -61,8 +61,9 @@ class MediaFile::Image < MediaFile
|
||||
if is_animated_gif?
|
||||
frame_count / duration
|
||||
elsif is_animated_png?
|
||||
# XXX we have to resort to ffprobe to get the frame rate because libvips and exiftool can't get it.
|
||||
video.frame_rate
|
||||
# XXX As with GIFs, animated PNGs can have an unspecified frame rate.
|
||||
# Assume 10FPS if the frame rate is unspecified.
|
||||
video.frame_rate.presence || 10.0
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user