Class: Abrizer::FfprobeInformer
- Inherits:
-
Object
- Object
- Abrizer::FfprobeInformer
- Defined in:
- lib/abrizer/ffprobe_informer.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#json_result ⇒ Object
readonly
Returns the value of attribute json_result.
Instance Method Summary collapse
- #audio_stream ⇒ Object
- #calculate_aspect_ratio_from_wh ⇒ Object
-
#display_aspect_ratio ⇒ Object
dar.
- #duration ⇒ Object
- #ffmpeg_info_cmd ⇒ Object
- #get_info ⇒ Object
- #height ⇒ Object
-
#initialize(filename) ⇒ FfprobeInformer
constructor
A new instance of FfprobeInformer.
- #to_s ⇒ Object
- #video_stream ⇒ Object
- #width ⇒ Object
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
#info ⇒ Object (readonly)
Returns the value of attribute info.
3 4 5 |
# File 'lib/abrizer/ffprobe_informer.rb', line 3 def info @info end |
#json_result ⇒ Object (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_stream ⇒ Object
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_wh ⇒ Object
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_ratio ⇒ Object
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 |
#duration ⇒ Object
22 23 24 |
# File 'lib/abrizer/ffprobe_informer.rb', line 22 def duration video_stream['duration'] if video_stream end |
#ffmpeg_info_cmd ⇒ Object
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_info ⇒ Object
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 |
#height ⇒ Object
18 19 20 |
# File 'lib/abrizer/ffprobe_informer.rb', line 18 def height video_stream['height'] if video_stream end |
#to_s ⇒ Object
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_stream ⇒ Object
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 |
#width ⇒ Object
14 15 16 |
# File 'lib/abrizer/ffprobe_informer.rb', line 14 def width video_stream['width'] if video_stream end |