mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-28 12:00:36 +01:00
Fix division by zero on some video/GIF files (#30600)
This commit is contained in:
parent
6f2a3fa5d1
commit
a2c7f7f690
1 changed files with 8 additions and 2 deletions
|
@ -41,8 +41,8 @@ class VideoMetadataExtractor
|
||||||
@colorspace = video_stream[:pix_fmt]
|
@colorspace = video_stream[:pix_fmt]
|
||||||
@width = video_stream[:width]
|
@width = video_stream[:width]
|
||||||
@height = video_stream[:height]
|
@height = video_stream[:height]
|
||||||
@frame_rate = video_stream[:avg_frame_rate] == '0/0' ? nil : Rational(video_stream[:avg_frame_rate])
|
@frame_rate = parse_framerate(video_stream[:avg_frame_rate])
|
||||||
@r_frame_rate = video_stream[:r_frame_rate] == '0/0' ? nil : Rational(video_stream[:r_frame_rate])
|
@r_frame_rate = parse_framerate(video_stream[:r_frame_rate])
|
||||||
# For some video streams the frame_rate reported by `ffprobe` will be 0/0, but for these streams we
|
# For some video streams the frame_rate reported by `ffprobe` will be 0/0, but for these streams we
|
||||||
# should use `r_frame_rate` instead. Video screencast generated by Gnome Screencast have this issue.
|
# should use `r_frame_rate` instead. Video screencast generated by Gnome Screencast have this issue.
|
||||||
@frame_rate ||= @r_frame_rate
|
@frame_rate ||= @r_frame_rate
|
||||||
|
@ -55,4 +55,10 @@ class VideoMetadataExtractor
|
||||||
|
|
||||||
@invalid = true if @metadata.key?(:error)
|
@invalid = true if @metadata.key?(:error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_framerate(raw)
|
||||||
|
Rational(raw)
|
||||||
|
rescue ZeroDivisionError
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue