mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Cope with videos with undefined display aspect ratios
This commit is contained in:
parent
9bf41f2495
commit
cf1c48478d
3 changed files with 15 additions and 2 deletions
|
@ -55,8 +55,12 @@ module ActiveStorage
|
||||||
|
|
||||||
def display_aspect_ratio
|
def display_aspect_ratio
|
||||||
if descriptor = video_stream["display_aspect_ratio"]
|
if descriptor = video_stream["display_aspect_ratio"]
|
||||||
terms = descriptor.split(":", 2).collect(&:to_i)
|
if terms = descriptor.split(":", 2)
|
||||||
terms if terms.count == 2 && terms.min >= 0
|
numerator = Integer(terms[0])
|
||||||
|
denominator = Integer(terms[1])
|
||||||
|
|
||||||
|
[numerator, denominator] unless numerator == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,15 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
|
||||||
assert_equal [16, 9], metadata[:display_aspect_ratio]
|
assert_equal [16, 9], metadata[:display_aspect_ratio]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "analyzing a video with an undefined display aspect ratio" do
|
||||||
|
blob = create_file_blob(filename: "video_with_undefined_display_aspect_ratio.mp4", content_type: "video/mp4")
|
||||||
|
metadata = extract_metadata_from(blob)
|
||||||
|
|
||||||
|
assert_equal 640, metadata[:width]
|
||||||
|
assert_equal 480, metadata[:height]
|
||||||
|
assert_nil metadata[:display_aspect_ratio]
|
||||||
|
end
|
||||||
|
|
||||||
test "analyzing a video without a video stream" do
|
test "analyzing a video without a video stream" do
|
||||||
blob = create_file_blob(filename: "video_without_video_stream.mp4", content_type: "video/mp4")
|
blob = create_file_blob(filename: "video_without_video_stream.mp4", content_type: "video/mp4")
|
||||||
metadata = extract_metadata_from(blob)
|
metadata = extract_metadata_from(blob)
|
||||||
|
|
BIN
activestorage/test/fixtures/files/video_with_undefined_display_aspect_ratio.mp4
vendored
Normal file
BIN
activestorage/test/fixtures/files/video_with_undefined_display_aspect_ratio.mp4
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue