aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/analyzer/video_analyzer_test.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2017-10-22 13:16:59 -0400
committerGitHub <noreply@github.com>2017-10-22 13:16:59 -0400
commit605484079d297d1ba6835628465be81f03c052ee (patch)
treee4e32f5e47f4bf48cb9eb9fc8d80c7da268ae262 /activestorage/test/analyzer/video_analyzer_test.rb
parent6525e7fb2e534a6564438008f9c02cf29eb37483 (diff)
downloadrails-605484079d297d1ba6835628465be81f03c052ee.tar.gz
rails-605484079d297d1ba6835628465be81f03c052ee.tar.bz2
rails-605484079d297d1ba6835628465be81f03c052ee.zip
Extract metadata from images and videos
Diffstat (limited to 'activestorage/test/analyzer/video_analyzer_test.rb')
-rw-r--r--activestorage/test/analyzer/video_analyzer_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/activestorage/test/analyzer/video_analyzer_test.rb b/activestorage/test/analyzer/video_analyzer_test.rb
new file mode 100644
index 0000000000..4a3c4a8bfc
--- /dev/null
+++ b/activestorage/test/analyzer/video_analyzer_test.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require "database/setup"
+
+require "active_storage/analyzer/video_analyzer"
+
+class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
+ test "analyzing a video" do
+ blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4")
+ metadata = blob.tap(&:analyze).metadata
+
+ assert_equal 640, metadata[:width]
+ assert_equal 480, metadata[:height]
+ assert_equal [4, 3], metadata[:aspect_ratio]
+ assert_equal 5.166648, metadata[:duration]
+ assert_not_includes metadata, :angle
+ end
+
+ test "analyzing a rotated video" do
+ 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 [4, 3], metadata[:aspect_ratio]
+ assert_equal 5.227975, metadata[:duration]
+ assert_equal 90, metadata[:angle]
+ end
+
+ test "analyzing a video without a video stream" do
+ blob = create_file_blob(filename: "video_without_video_stream.mp4", content_type: "video/mp4")
+ assert_equal({ "analyzed" => true }, blob.tap(&:analyze).metadata)
+ end
+end