Class: FFmpegCore::Probe
- Inherits:
-
Object
- Object
- FFmpegCore::Probe
- Defined in:
- lib/ffmpeg_core/probe.rb
Overview
Probe video metadata using ffprobe
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #audio_codec ⇒ Object
-
#audio_stream ⇒ Object
Audio stream metadata.
-
#bitrate ⇒ Object
Bitrate in kb/s.
-
#duration ⇒ Object
Duration in seconds.
- #frame_rate ⇒ Object
- #height ⇒ Object
-
#initialize(path) ⇒ Probe
constructor
A new instance of Probe.
- #resolution ⇒ Object
- #valid? ⇒ Boolean
- #video_codec ⇒ Object
-
#video_stream ⇒ Object
Video stream metadata.
- #width ⇒ Object
Constructor Details
#initialize(path) ⇒ Probe
Returns a new instance of Probe.
11 12 13 14 15 16 |
# File 'lib/ffmpeg_core/probe.rb', line 11 def initialize(path) @path = path.to_s @metadata = nil validate_file! probe! end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/ffmpeg_core/probe.rb', line 9 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/ffmpeg_core/probe.rb', line 9 def path @path end |
Instance Method Details
#audio_codec ⇒ Object
42 43 44 |
# File 'lib/ffmpeg_core/probe.rb', line 42 def audio_codec audio_stream&.dig("codec_name") end |
#audio_stream ⇒ Object
Audio stream metadata
34 35 36 |
# File 'lib/ffmpeg_core/probe.rb', line 34 def audio_stream @audio_stream ||= streams.find { |s| s["codec_type"] == "audio" } end |
#bitrate ⇒ Object
Bitrate in kb/s
24 25 26 |
# File 'lib/ffmpeg_core/probe.rb', line 24 def bitrate @metadata.dig("format", "bit_rate")&.to_i&./(1000) end |
#duration ⇒ Object
Duration in seconds
19 20 21 |
# File 'lib/ffmpeg_core/probe.rb', line 19 def duration @metadata.dig("format", "duration")&.to_f end |
#frame_rate ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ffmpeg_core/probe.rb', line 54 def frame_rate return nil unless video_stream # Parse frame rate (e.g., "30000/1001" or "30") r_frame_rate = video_stream["r_frame_rate"] return nil unless r_frame_rate if r_frame_rate.include?("/") num, den = r_frame_rate.split("/").map(&:to_f) num / den else r_frame_rate.to_f end end |
#height ⇒ Object
50 51 52 |
# File 'lib/ffmpeg_core/probe.rb', line 50 def height video_stream&.dig("height") end |
#resolution ⇒ Object
69 70 71 72 |
# File 'lib/ffmpeg_core/probe.rb', line 69 def resolution return nil unless width && height "#{width}x#{height}" end |
#valid? ⇒ Boolean
74 75 76 |
# File 'lib/ffmpeg_core/probe.rb', line 74 def valid? !video_stream.nil? end |
#video_codec ⇒ Object
38 39 40 |
# File 'lib/ffmpeg_core/probe.rb', line 38 def video_codec video_stream&.dig("codec_name") end |
#video_stream ⇒ Object
Video stream metadata
29 30 31 |
# File 'lib/ffmpeg_core/probe.rb', line 29 def video_stream @video_stream ||= streams.find { |s| s["codec_type"] == "video" } end |
#width ⇒ Object
46 47 48 |
# File 'lib/ffmpeg_core/probe.rb', line 46 def width video_stream&.dig("width") end |