lib/aviglitch/frames.rb in aviglitch-0.1.1 vs lib/aviglitch/frames.rb in aviglitch-0.1.2

- old
+ new

@@ -43,12 +43,13 @@ :flag => io.read(4).unpack('V').first, :offset => io.read(4).unpack('V').first, :size => io.read(4).unpack('V').first, } end + fix_offsets_if_needed io unless safe_frames_count? @meta.size - @io.close! + io.close! exit end io.rewind @io = io end @@ -76,10 +77,12 @@ block.call(frame) if block # accept the variable block as Proc yield frame if block_given? # or a given block (or do nothing) unless frame.data.nil? m[:offset] = io.pos + 4 # 4 for 'movi' m[:size] = frame.data.size + m[:flag] = frame.flag + m[:id] = frame.id io.print m[:id] io.print [frame.data.size].pack('V') io.print frame.data io.print "\000" if frame.data.size % 2 == 1 true @@ -319,10 +322,21 @@ def delete_at n self.slice! n end ## + # Modify keyframes to deltaframes at given range, or all. + def clear_keyframes! range = nil + range = 0..self.size if range.nil? + self.each_with_index do |frame, i| + if range.include? i + frame.flag = 0 if frame.is_keyframe? + end + end + end + + ## # Returns true if +other+'s frames are same as self's frames. def == other @meta == other.meta end @@ -330,10 +344,14 @@ # Generates new AviGlitch::Base instance using self. def to_avi AviGlitch.open @io.path end + def inspect # :nodec: + "#<#{self.class.name}:#{sprintf("0x%x", object_id)} @io=#{@io.inspect} size=#{self.size}>" + end + def get_beginning_and_length *args #:nodoc: b, l = args if args.first.kind_of? Range r = args.first b = r.begin @@ -360,9 +378,23 @@ @@warn_if_frames_are_too_large = !r end r end + def fix_offsets_if_needed io #:nodoc: + # rarely data offsets begin from 0 of the file + return if @meta.empty? + pos = io.pos + m = @meta.first + io.pos = @pos_of_movi + m[:offset] + unless io.read(4) == m[:id] + @meta.each do |x| + x[:offset] -= @pos_of_movi + end + end + io.pos = pos + end + protected :frames_data_as_io, :meta - private :overwrite, :get_beginning_and_length + private :overwrite, :get_beginning_and_length, :fix_offsets_if_needed end end