Sha256: 50d92d60eaf70fa9701dc509c8139a2878d73f999638fd64ffa407ef456dba0e
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
module Ffprober class Parser @@options = '-v quiet -print_format json -show_format -show_streams' class << self def from_file(file_to_parse) unless FfprobeVersion.valid? raise ArgumentError.new("no or unsupported ffprobe version found.\ (version: #{FfprobeVersion.new.version.to_s})") end json_output = `#{Ffprober.path} #{@@options} '#{file_to_parse}'` from_json(json_output) end def from_json(json_to_parse) parser = self.new parser.parse(json_to_parse) parser end end def parse(json_to_parse) raise ArgumentError.new("No JSON found") if json_to_parse.nil? @json_to_parse = json_to_parse end def parsed_json @parsed_json ||= begin json = JSON.parse(@json_to_parse, symbolize_names: true) raise InvalidInputFileError.new("Invalid input file") if json.empty? json end end def format @format ||= Ffprober::Format.new(parsed_json[:format]) end def video_streams @video_streams ||= stream_by_codec('video').map { |s| Ffprober::VideoStream.new(s) } end def audio_streams @audio_streams ||= stream_by_codec('audio').map { |s| Ffprober::AudioStream.new(s) } end def stream_by_codec(codec_type) streams.select { |stream| stream[:codec_type] == codec_type } end def streams parsed_json[:streams] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ffprober-0.3.7 | lib/ffprober/parser.rb |
ffprober-0.3.6 | lib/ffprober/parser.rb |