2017-10-22 13:16:59 -04:00
|
|
|
# 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")
|
2018-01-19 10:47:18 -05:00
|
|
|
metadata = extract_metadata_from(blob)
|
2017-10-22 13:16:59 -04:00
|
|
|
|
|
|
|
assert_equal 640, metadata[:width]
|
|
|
|
assert_equal 480, metadata[:height]
|
2018-01-19 10:47:18 -05:00
|
|
|
assert_equal [4, 3], metadata[:display_aspect_ratio]
|
2019-07-16 20:59:03 -04:00
|
|
|
assert_equal 5.166648, metadata[:duration]
|
2017-10-22 13:16:59 -04:00
|
|
|
assert_not_includes metadata, :angle
|
|
|
|
end
|
|
|
|
|
|
|
|
test "analyzing a rotated video" do
|
|
|
|
blob = create_file_blob(filename: "rotated_video.mp4", content_type: "video/mp4")
|
2018-01-19 10:47:18 -05:00
|
|
|
metadata = extract_metadata_from(blob)
|
2017-10-22 13:16:59 -04:00
|
|
|
|
2017-12-08 13:15:04 -05:00
|
|
|
assert_equal 480, metadata[:width]
|
|
|
|
assert_equal 640, metadata[:height]
|
2018-01-19 10:47:18 -05:00
|
|
|
assert_equal [4, 3], metadata[:display_aspect_ratio]
|
2017-10-22 13:16:59 -04:00
|
|
|
assert_equal 90, metadata[:angle]
|
|
|
|
end
|
|
|
|
|
2018-01-19 10:47:18 -05:00
|
|
|
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)
|
|
|
|
|
|
|
|
assert_equal 1280, metadata[:width]
|
|
|
|
assert_equal 720, metadata[:height]
|
|
|
|
assert_equal [16, 9], metadata[:display_aspect_ratio]
|
|
|
|
end
|
|
|
|
|
2018-01-20 14:47:04 -05:00
|
|
|
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
|
|
|
|
|
2017-10-22 13:16:59 -04:00
|
|
|
test "analyzing a video without a video stream" do
|
|
|
|
blob = create_file_blob(filename: "video_without_video_stream.mp4", content_type: "video/mp4")
|
2018-01-19 18:46:59 -05:00
|
|
|
metadata = extract_metadata_from(blob)
|
|
|
|
assert_equal({ "analyzed" => true, "identified" => true }, metadata)
|
2017-10-22 13:16:59 -04:00
|
|
|
end
|
|
|
|
end
|