Class: ActiveStorageValidations::Analyzer::VideoAnalyzer

Inherits:
ActiveStorageValidations::Analyzer show all
Includes:
ActiveStorageValidations::ASVFFProbable
Defined in:
lib/active_storage_validations/analyzer/video_analyzer.rb

Overview

ActiveStorageValidations Video Analyzer

Extracts the following from a video attachable:

  • Width (pixels)
  • Height (pixels)
  • Duration (seconds)
  • Angle (degrees)
  • Audio (true if file has an audio channel, false if not)
  • Video (true if file has an video channel, false if not)

Example:

ActiveStorageValidations::Analyzer::VideoAnalyzer.new(attachable).
# => { width: 640, height: 480, duration: 5.0, angle: 0, audio: true, video: true }

When a video's angle is 90, -90, 270 or -270 degrees, its width and height are automatically swapped for convenience.

This analyzer requires the FFmpeg[https://www.ffmpeg.org] system library, which is not provided by Rails.

Instance Attribute Summary

Attributes inherited from ActiveStorageValidations::Analyzer

#attachable

Instance Method Summary collapse

Methods inherited from ActiveStorageValidations::Analyzer

#content_type, #initialize

Methods included from ActiveStorageValidations::ASVLoggable

#logger

Constructor Details

This class inherits a constructor from ActiveStorageValidations::Analyzer

Instance Method Details

#metadataObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_storage_validations/analyzer/video_analyzer.rb', line 29

def 
  read_media do |media|
    {
      width: (Integer(width) if width),
      height: (Integer(height) if height),
      duration: duration,
      angle: angle,
      audio: audio?,
      video: video?
    }.compact
  end
end