Class: Abrizer::FfprobeInformer

Inherits:
Object
  • Object
show all
Defined in:
lib/abrizer/ffprobe_informer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ FfprobeInformer

Returns a new instance of FfprobeInformer.



4
5
6
7
# File 'lib/abrizer/ffprobe_informer.rb', line 4

def initialize(filename)
  @filename = filename
  get_info
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



3
4
5
# File 'lib/abrizer/ffprobe_informer.rb', line 3

def info
  @info
end

#json_resultObject (readonly)

Returns the value of attribute json_result.



3
4
5
# File 'lib/abrizer/ffprobe_informer.rb', line 3

def json_result
  @json_result
end

Instance Method Details

#audio_streamObject



57
58
59
60
61
# File 'lib/abrizer/ffprobe_informer.rb', line 57

def audio_stream
  @info['streams'].find do |stream|
    stream['codec_type'] == 'audio'
  end
end

#calculate_aspect_ratio_from_whObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/abrizer/ffprobe_informer.rb', line 36

def calculate_aspect_ratio_from_wh
  new_width = width
  new_height = height
  w = width
  h = height
  while h != 0
    rem = w % h
    w = h
    h = rem
  end
  new_height = new_height / w
  new_width = new_width / w
  "#{new_width}:#{new_height}"
end

#display_aspect_ratioObject

dar



26
27
28
29
30
31
32
33
34
# File 'lib/abrizer/ffprobe_informer.rb', line 26

def display_aspect_ratio #dar
  dar = video_stream['display_aspect_ratio']
  sar = video_stream['sample_aspect_ratio']
  if dar == "0:1" #&& sar == "0:1"
    calculate_aspect_ratio_from_wh
  else
    dar
  end
end

#durationObject



22
23
24
# File 'lib/abrizer/ffprobe_informer.rb', line 22

def duration
  video_stream['duration'] if video_stream
end

#ffmpeg_info_cmdObject



63
64
65
# File 'lib/abrizer/ffprobe_informer.rb', line 63

def ffmpeg_info_cmd
  "ffprobe -v error -print_format json -show_format -show_streams #{@filename}"
end

#get_infoObject



9
10
11
12
# File 'lib/abrizer/ffprobe_informer.rb', line 9

def get_info
  @json_result = `#{ffmpeg_info_cmd}`
  @info = MultiJson.load @json_result
end

#heightObject



18
19
20
# File 'lib/abrizer/ffprobe_informer.rb', line 18

def height
  video_stream['height'] if video_stream
end

#to_sObject



67
68
69
70
# File 'lib/abrizer/ffprobe_informer.rb', line 67

def to_s
  ffmpeg_info_cmd + "\n" +
  "#{width}x#{height} DAR:#{display_aspect_ratio}"
end

#video_streamObject



51
52
53
54
55
# File 'lib/abrizer/ffprobe_informer.rb', line 51

def video_stream
  @info['streams'].find do |stream|
    stream['codec_type'] == 'video'
  end
end

#widthObject



14
15
16
# File 'lib/abrizer/ffprobe_informer.rb', line 14

def width
  video_stream['width'] if video_stream
end