Class: Ffprober::Parser
- Inherits:
-
Object
- Object
- Ffprober::Parser
- Defined in:
- lib/ffprober/parser.rb
Class Method Summary collapse
Instance Method Summary collapse
- #audio_streams ⇒ Object
- #chapters ⇒ Object
- #format ⇒ Object
- #parse(json_to_parse) ⇒ Object
- #video_streams ⇒ Object
Class Method Details
.from_file(file_to_parse) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ffprober/parser.rb', line 3 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} '#{file_to_parse}'` from_json(json_output) end |
.from_json(json_to_parse) ⇒ Object
17 18 19 20 21 |
# File 'lib/ffprober/parser.rb', line 17 def self.from_json(json_to_parse) parser = new parser.parse(json_to_parse) parser end |
Instance Method Details
#audio_streams ⇒ Object
36 37 38 |
# File 'lib/ffprober/parser.rb', line 36 def audio_streams @audio_streams ||= stream_by_codec('audio').map { |stream| Ffprober::AudioStream.new(stream) } end |
#chapters ⇒ Object
40 41 42 |
# File 'lib/ffprober/parser.rb', line 40 def chapters @chapters ||= @json[:chapters].map { |chapter| Ffprober::Chapter.new(chapter) } end |
#format ⇒ Object
28 29 30 |
# File 'lib/ffprober/parser.rb', line 28 def format @format ||= Ffprober::Format.new(@json[:format]) end |
#parse(json_to_parse) ⇒ Object
23 24 25 26 |
# File 'lib/ffprober/parser.rb', line 23 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 |
#video_streams ⇒ Object
32 33 34 |
# File 'lib/ffprober/parser.rb', line 32 def video_streams @video_streams ||= stream_by_codec('video').map { |stream| Ffprober::VideoStream.new(stream) } end |