aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2017-12-08 13:15:04 -0500
committerGeorge Claghorn <george@basecamp.com>2017-12-08 13:15:04 -0500
commitda8e0ba03cbae33857954c0c1a228bd6dae562da (patch)
tree624c4efb44e7b18ea4e5b1b04bca81d025026bac
parent131cc6eab64eeae6c7f508dca4176183144cf3a6 (diff)
downloadrails-da8e0ba03cbae33857954c0c1a228bd6dae562da.tar.gz
rails-da8e0ba03cbae33857954c0c1a228bd6dae562da.tar.bz2
rails-da8e0ba03cbae33857954c0c1a228bd6dae562da.zip
Swap raw video width and height if angle is 90 or 270 degrees
-rw-r--r--activestorage/lib/active_storage/analyzer/video_analyzer.rb14
-rw-r--r--activestorage/test/analyzer/video_analyzer_test.rb4
2 files changed, 15 insertions, 3 deletions
diff --git a/activestorage/lib/active_storage/analyzer/video_analyzer.rb b/activestorage/lib/active_storage/analyzer/video_analyzer.rb
index b6fc54d917..1c144baa37 100644
--- a/activestorage/lib/active_storage/analyzer/video_analyzer.rb
+++ b/activestorage/lib/active_storage/analyzer/video_analyzer.rb
@@ -31,10 +31,18 @@ module ActiveStorage
private
def width
- Integer(video_stream["width"]) if video_stream["width"]
+ rotated? ? raw_height : raw_width
end
def height
+ rotated? ? raw_width : raw_height
+ end
+
+ def raw_width
+ Integer(video_stream["width"]) if video_stream["width"]
+ end
+
+ def raw_height
Integer(video_stream["height"]) if video_stream["height"]
end
@@ -52,6 +60,10 @@ module ActiveStorage
end
end
+ def rotated?
+ angle == 90 || angle == 270
+ end
+
def tags
@tags ||= video_stream["tags"] || {}
diff --git a/activestorage/test/analyzer/video_analyzer_test.rb b/activestorage/test/analyzer/video_analyzer_test.rb
index 4a3c4a8bfc..b3b9c97fe4 100644
--- a/activestorage/test/analyzer/video_analyzer_test.rb
+++ b/activestorage/test/analyzer/video_analyzer_test.rb
@@ -21,8 +21,8 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
blob = create_file_blob(filename: "rotated_video.mp4", content_type: "video/mp4")
metadata = blob.tap(&:analyze).metadata
- assert_equal 640, metadata[:width]
- assert_equal 480, metadata[:height]
+ assert_equal 480, metadata[:width]
+ assert_equal 640, metadata[:height]
assert_equal [4, 3], metadata[:aspect_ratio]
assert_equal 5.227975, metadata[:duration]
assert_equal 90, metadata[:angle]