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
- #subtitle_streams ⇒ Object
- #video_streams ⇒ Object
Class Method Details
.from_file(file_to_parse) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ffprober/parser.rb', line 5 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 |
.from_json(json_to_parse) ⇒ Object
19 20 21 22 23 |
# File 'lib/ffprober/parser.rb', line 19 def self.from_json(json_to_parse) parser = new parser.parse(json_to_parse) parser end |
Instance Method Details
#audio_streams ⇒ Object
38 39 40 |
# File 'lib/ffprober/parser.rb', line 38 def audio_streams @audio_streams ||= stream_by_codec('audio').map { |stream| Ffprober::AudioStream.new(stream) } end |
#chapters ⇒ Object
46 47 48 |
# File 'lib/ffprober/parser.rb', line 46 def chapters @chapters ||= @json[:chapters].map { |chapter| Ffprober::Chapter.new(chapter) } end |
#format ⇒ Object
30 31 32 |
# File 'lib/ffprober/parser.rb', line 30 def format @format ||= Ffprober::Format.new(@json[:format]) end |
#parse(json_to_parse) ⇒ Object
25 26 27 28 |
# File 'lib/ffprober/parser.rb', line 25 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 |
#subtitle_streams ⇒ Object
42 43 44 |
# File 'lib/ffprober/parser.rb', line 42 def subtitle_streams @subtitle_streams ||= stream_by_codec('subtitle').map { |stream| Ffprober::SubtitleStream.new(stream) } end |
#video_streams ⇒ Object
34 35 36 |
# File 'lib/ffprober/parser.rb', line 34 def video_streams @video_streams ||= stream_by_codec('video').map { |stream| Ffprober::VideoStream.new(stream) } end |