class Abrizer::FfprobeInformer
Attributes
info[R]
json_result[R]
Public Class Methods
new(filepath: nil, output_directory: nil)
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 7 def initialize(filepath: nil, output_directory: nil) @filepath = filepath @output_directory = output_directory get_info end
Public Instance Methods
audio_stream()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 84 def audio_stream @info['streams'].find do |stream| stream['codec_type'] == 'audio' end end
calculate_aspect_ratio_from_wh()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 59 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()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 49 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()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 41 def duration if probe_format && probe_format['duration'] probe_format['duration'] elsif video_stream && video_stream['duration'] video_stream['duration'] end end
ffmpeg_info_cmd()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 90 def ffmpeg_info_cmd "ffprobe -v error -print_format json -show_format -show_streams #{@filepath}" end
get_info()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 13 def get_info if @filepath && File.exist?(@filepath) && !File.directory?(@filepath) get_info_with_command elsif @output_directory && File.exist?(ffprobe_filepath) get_info_from_file else raise FfprobeError end end
get_info_from_file()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 23 def get_info_from_file @json_result = File.read ffprobe_filepath @info = MultiJson.load @json_result end
get_info_with_command()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 28 def get_info_with_command @json_result = `#{ffmpeg_info_cmd}` @info = MultiJson.load @json_result end
height()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 37 def height video_stream['height'] if video_stream end
probe_format()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 80 def probe_format @info['format'] end
to_json()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 99 def to_json information = @info info_filename = information['format']['filename'] truncated_filename = File.basename info_filename information['format']['filename'] = truncated_filename MultiJson.dump information end
to_s()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 94 def to_s ffmpeg_info_cmd + "\n" + "#{width}x#{height} DAR:#{display_aspect_ratio}" end
video_stream()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 74 def video_stream @info['streams'].find do |stream| stream['codec_type'] == 'video' end end
width()
click to toggle source
# File lib/abrizer/ffprobe_informer.rb, line 33 def width video_stream['width'] if video_stream end