Sha256: 003459ec3cde30f076cb0a564e0494405a57152eba34439b66cefbb3f76b9e6b
Contents?: true
Size: 1.76 KB
Versions: 1
Compression:
Stored size: 1.76 KB
Contents
require 'shellwords' module Ffprober class Parser def self.from_file(file_to_parse) unless FfprobeVersion.valid? fail ArgumentError.new("no or unsupported ffprobe version found.\ (version: #{FfprobeVersion.new.version})") end unless File.exist?(file_to_parse) fail ArgumentError.new("File not found #{file_to_parse}") end json_output = `#{Ffprober.path} #{options} #{Shellwords.escape(file_to_parse)}` from_json(json_output) end def self.from_json(json_to_parse) parser = new parser.parse(json_to_parse) parser end def parse(json_to_parse) fail ArgumentError.new('No JSON input data') if json_to_parse.nil? @json = JSON.parse(json_to_parse, symbolize_names: true) end def format @format ||= Ffprober::Format.new(@json[:format]) end def video_streams @video_streams ||= stream_by_codec('video').map { |stream| Ffprober::VideoStream.new(stream) } end def audio_streams @audio_streams ||= stream_by_codec('audio').map { |stream| Ffprober::AudioStream.new(stream) } end def subtitle_streams @subtitle_streams ||= stream_by_codec('subtitle').map { |stream| Ffprober::SubtitleStream.new(stream) } end def chapters @chapters ||= @json[:chapters].map { |chapter| Ffprober::Chapter.new(chapter) } end private def self.options options = '-v quiet -print_format json -show_format -show_streams' options << ' -show_chapters' if FfprobeVersion.version >= Gem::Version.new('2.0.0') options end def stream_by_codec(codec_type) streams.select { |stream| stream[:codec_type] == codec_type } end def streams @json[:streams] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ffprober-0.4.2 | lib/ffprober/parser.rb |