diff --git a/activestorage/lib/active_storage/analyzer/video_analyzer.rb b/activestorage/lib/active_storage/analyzer/video_analyzer.rb index fea4007d94f..51c1b76dc15 100644 --- a/activestorage/lib/active_storage/analyzer/video_analyzer.rb +++ b/activestorage/lib/active_storage/analyzer/video_analyzer.rb @@ -55,11 +55,15 @@ module ActiveStorage def angle if tags["rotate"] Integer(tags["rotate"]) - elsif side_data && side_data[0] && side_data[0]["rotation"] - Integer(side_data[0]["rotation"]) + elsif display_matrix && display_matrix["rotation"] + Integer(display_matrix["rotation"]) end end + def display_matrix + side_data.detect { |data| data["side_data_type"] == "Display Matrix" } + end + def display_aspect_ratio if descriptor = video_stream["display_aspect_ratio"] if terms = descriptor.split(":", 2) diff --git a/activestorage/test/analyzer/video_analyzer_test.rb b/activestorage/test/analyzer/video_analyzer_test.rb index 58ccb484ff0..b92e13b0547 100644 --- a/activestorage/test/analyzer/video_analyzer_test.rb +++ b/activestorage/test/analyzer/video_analyzer_test.rb @@ -29,6 +29,15 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase assert_includes [90, -90], metadata[:angle] end + test "analyzing a rotated HDR video" do + blob = create_file_blob(filename: "rotated_hdr_video.mov", content_type: "video/quicktime") + metadata = extract_metadata_from(blob) + + assert_equal 1080.0, metadata[:width] + assert_equal 1920.0, metadata[:height] + assert_equal(-90, metadata[:angle]) + end + test "analyzing a video with rectangular samples" do blob = create_file_blob(filename: "video_with_rectangular_samples.mp4", content_type: "video/mp4") metadata = extract_metadata_from(blob) diff --git a/activestorage/test/fixtures/files/rotated_hdr_video.mov b/activestorage/test/fixtures/files/rotated_hdr_video.mov new file mode 100644 index 00000000000..c1a04b7cdb6 Binary files /dev/null and b/activestorage/test/fixtures/files/rotated_hdr_video.mov differ