Class: Yamdi
- Inherits:
-
Object
- Object
- Yamdi
- Defined in:
- lib/yamdi.rb
Instance Method Summary collapse
- #audio_codec_id ⇒ Object
- #audio_data_rate ⇒ Object
- #audio_delay ⇒ Object
- #audio_sample_rate ⇒ Object
- #audio_sample_size ⇒ Object
- #audio_size ⇒ Object
- #can_seek_to_end? ⇒ Boolean
- #data_size ⇒ Object
- #duration ⇒ Object
- #file_size ⇒ Object
- #frame_rate ⇒ Object
- #has_audio? ⇒ Boolean
- #has_cue_points? ⇒ Boolean
- #has_keyframes? ⇒ Boolean
- #has_metadata? ⇒ Boolean
- #has_video? ⇒ Boolean
- #height ⇒ Object
-
#initialize(flv_path) ⇒ Yamdi
constructor
A new instance of Yamdi.
- #key_frames ⇒ Object
- #last_key_frame_location ⇒ Object
- #last_key_frame_timestamp ⇒ Object
- #last_timestamp ⇒ Object
- #last_video_frame_timestamp ⇒ Object
- #parse(flv_path) ⇒ Object
- #stereo? ⇒ Boolean
- #video_codec_id ⇒ Object
- #video_data_rate ⇒ Object
- #video_size ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(flv_path) ⇒ Yamdi
Returns a new instance of Yamdi.
6 7 8 |
# File 'lib/yamdi.rb', line 6 def initialize(flv_path) @metadata = Nokogiri.parse( parse(flv_path) ) end |
Instance Method Details
#audio_codec_id ⇒ Object
46 47 48 |
# File 'lib/yamdi.rb', line 46 def audio_codec_id @metadata.xpath("//audiocodecid").inner_text.to_i end |
#audio_data_rate ⇒ Object
54 55 56 |
# File 'lib/yamdi.rb', line 54 def audio_data_rate @metadata.xpath("//audiodatarate").inner_text.to_i end |
#audio_delay ⇒ Object
62 63 64 |
# File 'lib/yamdi.rb', line 62 def audio_delay @metadata.xpath("//audiodelay").inner_text.to_f end |
#audio_sample_rate ⇒ Object
50 51 52 |
# File 'lib/yamdi.rb', line 50 def audio_sample_rate @metadata.xpath("//audiosamplerate").inner_text.to_i end |
#audio_sample_size ⇒ Object
58 59 60 |
# File 'lib/yamdi.rb', line 58 def audio_sample_size @metadata.xpath("//audiosamplesize").inner_text.to_i end |
#audio_size ⇒ Object
94 95 96 |
# File 'lib/yamdi.rb', line 94 def audio_size @metadata.xpath("//audiosize").inner_text.to_i end |
#can_seek_to_end? ⇒ Boolean
42 43 44 |
# File 'lib/yamdi.rb', line 42 def can_seek_to_end? boolean @metadata.xpath("//canSeekToEnd").inner_text end |
#data_size ⇒ Object
90 91 92 |
# File 'lib/yamdi.rb', line 90 def data_size @metadata.xpath("//datasize").inner_text.to_i end |
#duration ⇒ Object
18 19 20 |
# File 'lib/yamdi.rb', line 18 def duration @metadata.xpath("//duration").inner_text.to_f end |
#file_size ⇒ Object
102 103 104 |
# File 'lib/yamdi.rb', line 102 def file_size @metadata.xpath("//filesize").inner_text.to_i end |
#frame_rate ⇒ Object
74 75 76 |
# File 'lib/yamdi.rb', line 74 def frame_rate @metadata.xpath("//framerate").inner_text.to_f end |
#has_audio? ⇒ Boolean
30 31 32 |
# File 'lib/yamdi.rb', line 30 def has_audio? boolean @metadata.xpath("//hasAudio").inner_text end |
#has_cue_points? ⇒ Boolean
38 39 40 |
# File 'lib/yamdi.rb', line 38 def has_cue_points? boolean @metadata.xpath("//hasCuePoints").inner_text end |
#has_keyframes? ⇒ Boolean
22 23 24 |
# File 'lib/yamdi.rb', line 22 def has_keyframes? boolean @metadata.xpath("//hasKeyframes").inner_text end |
#has_metadata? ⇒ Boolean
34 35 36 |
# File 'lib/yamdi.rb', line 34 def boolean @metadata.xpath("//hasMetadata").inner_text end |
#has_video? ⇒ Boolean
26 27 28 |
# File 'lib/yamdi.rb', line 26 def has_video? boolean @metadata.xpath("//hasVideo").inner_text end |
#height ⇒ Object
82 83 84 |
# File 'lib/yamdi.rb', line 82 def height @metadata.xpath("//height").inner_text.to_i end |
#key_frames ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/yamdi.rb', line 122 def key_frames times_data_xml = @metadata.xpath("//keyframes/times/value") times = [] times_data_xml.children.each do |el| times << el.inner_text.to_f end file_positions_xml = @metadata.xpath("//keyframes/filepositions/value") file_positions = [] file_positions_xml.children.each do |el| file_positions << el.inner_text.to_i end count = 0 key_frames = [] while count < times.size do key_frames << OpenStruct.new(:time => times[count], :file_position => file_positions[count]) count = count + 1 end key_frames end |
#last_key_frame_location ⇒ Object
118 119 120 |
# File 'lib/yamdi.rb', line 118 def last_key_frame_location @metadata.xpath("//lastkeyframelocation").inner_text.to_i end |
#last_key_frame_timestamp ⇒ Object
114 115 116 |
# File 'lib/yamdi.rb', line 114 def @metadata.xpath("//lastkeyframetimestamp").inner_text.to_f end |
#last_timestamp ⇒ Object
106 107 108 |
# File 'lib/yamdi.rb', line 106 def @metadata.xpath("//lasttimestamp").inner_text.to_f end |
#last_video_frame_timestamp ⇒ Object
110 111 112 |
# File 'lib/yamdi.rb', line 110 def @metadata.xpath("//lastvideoframetimestamp").inner_text.to_f end |
#parse(flv_path) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/yamdi.rb', line 10 def parse(flv_path) temp_file = Tempfile.new('yamdi_tmp') `yamdi -i #{flv_path} -x #{temp_file.path}` contents = temp_file.read temp_file.close contents end |
#stereo? ⇒ Boolean
66 67 68 |
# File 'lib/yamdi.rb', line 66 def stereo? boolean @metadata.xpath("//stereo").inner_text end |
#video_codec_id ⇒ Object
70 71 72 |
# File 'lib/yamdi.rb', line 70 def video_codec_id @metadata.xpath("//videocodecid").inner_text.to_i end |
#video_data_rate ⇒ Object
78 79 80 |
# File 'lib/yamdi.rb', line 78 def video_data_rate @metadata.xpath("//videodatarate").inner_text.to_i end |
#video_size ⇒ Object
98 99 100 |
# File 'lib/yamdi.rb', line 98 def video_size @metadata.xpath("//videosize").inner_text.to_i end |
#width ⇒ Object
86 87 88 |
# File 'lib/yamdi.rb', line 86 def width @metadata.xpath("//width").inner_text.to_i end |