Skip to content

Commit

Permalink
Add frame data accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Sep 6, 2009
1 parent c0592c0 commit 0e13dcb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
23 changes: 22 additions & 1 deletion lib/ffmpeg/frame.rb
Expand Up @@ -68,12 +68,33 @@ class FFMPEG::Frame
}
C

##
# :method: data

builder.c <<-C
VALUE data() {
AVFrame *frame;
Data_Get_Struct(self, AVFrame, frame);
if (!frame->data)
return Qnil;
return rb_ary_new3(4,
rb_str_new((char *)frame->data[0], frame->linesize[0]),
rb_str_new((char *)frame->data[1], frame->linesize[1]),
rb_str_new((char *)frame->data[2], frame->linesize[2]),
rb_str_new((char *)frame->data[3], frame->linesize[3]));
}
C

##
# :method: key_frame

builder.c <<-C
VALUE key_frame() {
AVFrame *frame;
Data_Get_Struct(self, AVFrame, frame);
if (frame->key_frame)
Expand Down Expand Up @@ -135,8 +156,8 @@ class FFMPEG::Frame
end

attr_accessor :height
attr_accessor :pixel_format
attr_accessor :width
attr_accessor :pixel_format

def self.from(codec_context)
new codec_context.width, codec_context.height, codec_context.pixel_format
Expand Down
19 changes: 17 additions & 2 deletions test/test_ffmpeg_frame.rb
Expand Up @@ -5,7 +5,7 @@ class TestFFMPEGFrame < FFMPEG::TestCase
def setup
super

@frame = FFMPEG::Frame.new 40, 30, FFMPEG::PixelFormat::RGBA
@frame = FFMPEG::Frame.new 40, 30, FFMPEG::PixelFormat::YUV420P
@frame.defaults
end

Expand All @@ -19,6 +19,18 @@ def test_class_from
assert_equal FFMPEG::PixelFormat::YUV420P, frame.pixel_format
end

def test_data
@frame.fill

data = @frame.data

assert_equal 4, data.length
assert_equal 40, data[0].length
assert_equal 20, data[1].length
assert_equal 20, data[2].length
assert_equal 0, data[3].length
end

def test_defaults
@frame.defaults

Expand All @@ -28,8 +40,11 @@ def test_defaults
end

def test_fill
# this test sucks
assert_equal [ 0, 0, 0, 0], @frame.data.map { |d| d.length }

@frame.fill

assert_equal [40, 20, 20, 0], @frame.data.map { |d| d.length }
end

def test_key_frame
Expand Down

0 comments on commit 0e13dcb

Please sign in to comment.