Add metadata value for presence of video channel in video blobs

This commit is contained in:
Breno Gazzola 2021-06-09 10:56:52 -03:00
parent cde84b85eb
commit 48a7ec49bf
4 changed files with 20 additions and 3 deletions

View File

@ -1,3 +1,10 @@
* Add metadata value for presence of video channel in video blobs
The `metadata` attribute of video blobs has a new boolean key named `video` that is set to
`true` if the file has an video channel and `false` if it doesn't.
*Breno Gazzola*
* Deprecate usage of `purge` and `purge_later` from the association extension.
*Jacopo Beschi*

View File

@ -9,11 +9,12 @@ module ActiveStorage
# * Angle (degrees)
# * Display aspect ratio
# * Audio (true if file has an audio channel, false if not)
# * Video (true if file has an video channel, false if not)
#
# Example:
#
# ActiveStorage::Analyzer::VideoAnalyzer.new(blob).metadata
# # => { width: 640.0, height: 480.0, duration: 5.0, angle: 0, display_aspect_ratio: [4, 3], audio: true }
# # => { width: 640.0, height: 480.0, duration: 5.0, angle: 0, display_aspect_ratio: [4, 3], audio: true, video: true }
#
# When a video's angle is 90 or 270 degrees, its width and height are automatically swapped for convenience.
#
@ -24,7 +25,7 @@ module ActiveStorage
end
def metadata
{ width: width, height: height, duration: duration, angle: angle, display_aspect_ratio: display_aspect_ratio, audio: audio? }.compact
{ width: width, height: height, duration: duration, angle: angle, display_aspect_ratio: display_aspect_ratio, audio: audio?, video: video? }.compact
end
private
@ -72,6 +73,10 @@ module ActiveStorage
audio_stream.present?
end
def video?
video_stream.present?
end
def computed_height
if encoded_width && display_height_scale
encoded_width * display_height_scale

View File

@ -15,6 +15,7 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
assert_equal [4, 3], metadata[:display_aspect_ratio]
assert_equal 5.166648, metadata[:duration]
assert metadata[:audio]
assert metadata[:video]
assert_not_includes metadata, :angle
end
@ -54,6 +55,7 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
assert_equal 480, metadata[:height]
assert_equal 5.229000, metadata[:duration]
assert metadata[:audio]
assert metadata[:video]
end
test "analyzing a video without a video stream" do
@ -63,12 +65,15 @@ class ActiveStorage::Analyzer::VideoAnalyzerTest < ActiveSupport::TestCase
assert_not_includes metadata, :width
assert_not_includes metadata, :height
assert_equal 1.022000, metadata[:duration]
assert_not metadata[:video]
assert metadata[:audio]
end
test "analyzing a video without an audio stream" do
blob = create_file_blob(filename: "video_without_audio_stream.mp4", content_type: "video/mp4")
metadata = extract_metadata_from(blob)
assert metadata[:video]
assert_not metadata[:audio]
end
end

View File

@ -987,7 +987,7 @@ You can find more detailed configuration options in the
* `config.active_storage.variant_processor` accepts a symbol `:mini_magick` or `:vips`, specifying whether variant transformations will be performed with MiniMagick or ruby-vips. The default is `:mini_magick`.
* `config.active_storage.analyzers` accepts an array of classes indicating the analyzers available for Active Storage blobs. The default is `[ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer, ActiveStorage::Analyzer::AudioAnalyzer]`. The image analyzer can extract width and height of an image blob; the video analyzer can extract width, height, duration, angle, aspect ratio and presence/absence of audio channel of a video blob; the audio analyzer can extract duration and bit rate of an audio blob.
* `config.active_storage.analyzers` accepts an array of classes indicating the analyzers available for Active Storage blobs. The default is `[ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer, ActiveStorage::Analyzer::AudioAnalyzer]`. The image analyzer can extract width and height of an image blob; the video analyzer can extract width, height, duration, angle, aspect ratio and presence/absence of video/audio channels of a video blob; the audio analyzer can extract duration and bit rate of an audio blob.
* `config.active_storage.previewers` accepts an array of classes indicating the image previewers available in Active Storage blobs. The default is `[ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer]`. `PopplerPDFPreviewer` and `MuPDFPreviewer` can generate a thumbnail from the first page of a PDF blob; `VideoPreviewer` from the relevant frame of a video blob.