Class: ActiveStorageValidations::Analyzer::AudioAnalyzer

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

Overview

ActiveStorageValidations Audio Analyzer

Extracts the following from an audio attachable:

  • Duration (seconds)

  • Bit rate (bits/s)

  • Sample rate (hertz)

  • Tags (internal metadata)

Example:

ActiveStorageValidations::Analyzer::AudioAnalyzer.new(attachable).
# => { duration: 5.0, bit_rate: 320340, sample_rate: 44100, tags: { encoder: "Lavc57.64", ... } }

This analyzer requires the FFmpeg 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



25
26
27
28
29
30
31
32
33
34
# File 'lib/active_storage_validations/analyzer/audio_analyzer.rb', line 25

def 
  read_media do |media|
    {
      duration: duration,
      bit_rate: bit_rate,
      sample_rate: sample_rate,
      tags: tags
    }.compact
  end
end