Class: FFMPEG::ActiveStorage::Analyzer
- Inherits:
-
ActiveStorage::Analyzer
- Object
- ActiveStorage::Analyzer
- FFMPEG::ActiveStorage::Analyzer
- Defined in:
- lib/ffmpeg/active_storage/analyzer.rb
Overview
Active Storage Analyzer for video files using FFMPEG
This analyzer extracts video metadata that Active Storage can use for displaying video information and generating previews.
Class Method Summary collapse
-
.accept?(blob) ⇒ Boolean
Check if this analyzer can process the blob.
Instance Method Summary collapse
-
#metadata ⇒ Hash
Analyze the video and return metadata.
Class Method Details
.accept?(blob) ⇒ Boolean
Check if this analyzer can process the blob
21 22 23 |
# File 'lib/ffmpeg/active_storage/analyzer.rb', line 21 def accept?(blob) blob.video? end |
Instance Method Details
#metadata ⇒ Hash
Analyze the video and return metadata
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ffmpeg/active_storage/analyzer.rb', line 28 def download_blob_to_tempfile do |file| media = FFMPEG::Media.new(file.path) { width: media.width, height: media.height, duration: media.duration, angle: media.rotation, display_aspect_ratio: calculate_display_aspect_ratio(media), audio: media.audio?, video: media.video?, video_codec: media.video_codec, audio_codec: media.audio_codec, frame_rate: media.frame_rate, bit_rate: media.bit_rate }.compact end rescue FFMPEG::Error => e Rails.logger.error "[FFMPEG] Analysis failed: #{e.message}" if defined?(Rails) {} end |