lib/aviglitch/frames.rb in aviglitch-0.1.4 vs lib/aviglitch/frames.rb in aviglitch-0.1.5
- old
+ new
@@ -17,12 +17,15 @@
#
class Frames
include Enumerable
# :stopdoc:
+
+ ##
SAFE_FRAMES_COUNT = 150000
@@warn_if_frames_are_too_large = true
+
# :startdoc:
attr_reader :meta
##
@@ -59,11 +62,11 @@
##
# Enumerates the frames.
# It returns Enumerator if a block is not given.
def each
if block_given?
- temp = Tempfile.new 'frames'
+ temp = Tempfile.new 'frames', binmode: true
frames_data_as_io(temp, Proc.new)
overwrite temp
temp.close!
else
self.enum_for :each
@@ -84,11 +87,11 @@
Frame.new(nil, m[:id], m[:flag]).send detection
}.size
end
def frames_data_as_io io = nil, block = nil #:nodoc:
- io = Tempfile.new('tmep') if io.nil?
+ io = Tempfile.new('tmep', binmode: true) if io.nil?
@meta = @meta.select do |m|
@io.pos = @pos_of_movi + m[:offset] + 8 # 8 for id and size
frame = Frame.new(@io.read(m[:size]), m[:id], m[:flag])
block.call(frame) if block # accept the variable block as Proc
yield frame if block_given? # or a given block (or do nothing)
@@ -158,16 +161,15 @@
# Appends the frames in the other Frames into the tail of self.
# It is destructive like Array does.
def concat other_frames
raise TypeError unless other_frames.kind_of?(Frames)
# data
- this_data = Tempfile.new 'this'
+ this_data = Tempfile.new 'this', binmode: true
self.frames_data_as_io this_data
- other_data = Tempfile.new 'other'
+ other_data = Tempfile.new 'other', binmode: true
other_frames.frames_data_as_io other_data
- this_data.seek 0, IO::SEEK_END
- this_size = this_data.pos
+ this_size = this_data.size
other_data.rewind
while d = other_data.read(BUFFER_SIZE) do
this_data.print d
end
other_data.close!
@@ -179,10 +181,11 @@
end
@meta.concat other_meta
# close
overwrite this_data
this_data.close!
+ self
end
##
# Returns a concatenation of the two Frames as a new Frames instance.
def + other_frames
@@ -291,14 +294,13 @@
##
# Appends the given Frame into the tail of self.
def push frame
raise TypeError unless frame.kind_of? Frame
# data
- this_data = Tempfile.new 'this'
+ this_data = Tempfile.new 'this', binmode: true
self.frames_data_as_io this_data
- this_data.seek 0, IO::SEEK_END
- this_size = this_data.pos
+ this_size = this_data.size
this_data.print frame.id
this_data.print [frame.data.size].pack('V')
this_data.print frame.data
this_data.print "\000" if frame.data.size % 2 == 1
# meta
@@ -345,9 +347,10 @@
self.each_with_index do |frame, i|
if range.include? i
frame.flag = 0 if frame.is_keyframe?
end
end
+ self
end
##
# Returns true if +other+'s frames are same as self's frames.
def == other