Class: FFmpegCore::Probe

Inherits:
Object
  • Object
show all
Defined in:
lib/ffmpeg_core/probe.rb

Overview

Probe video metadata using ffprobe

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/ffmpeg_core/probe.rb', line 9

def 
  @metadata
end

#pathObject (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_codecObject



42
43
44
# File 'lib/ffmpeg_core/probe.rb', line 42

def audio_codec
  audio_stream&.dig("codec_name")
end

#audio_streamObject

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

#bitrateObject

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

#durationObject

Duration in seconds



19
20
21
# File 'lib/ffmpeg_core/probe.rb', line 19

def duration
  @metadata.dig("format", "duration")&.to_f
end

#frame_rateObject



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

#heightObject



50
51
52
# File 'lib/ffmpeg_core/probe.rb', line 50

def height
  video_stream&.dig("height")
end

#resolutionObject



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

Returns:

  • (Boolean)


74
75
76
# File 'lib/ffmpeg_core/probe.rb', line 74

def valid?
  !video_stream.nil?
end

#video_codecObject



38
39
40
# File 'lib/ffmpeg_core/probe.rb', line 38

def video_codec
  video_stream&.dig("codec_name")
end

#video_streamObject

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

#widthObject



46
47
48
# File 'lib/ffmpeg_core/probe.rb', line 46

def width
  video_stream&.dig("width")
end