Skip to content
Browse files

Add frame data accessor

  • Loading branch information...
1 parent c0592c0 commit 0e13dcb5bda8880018b870311511e4e6cebd6e80 @drbrain committed Sep 6, 2009
Showing with 39 additions and 3 deletions.
  1. +22 −1 lib/ffmpeg/frame.rb
  2. +17 −2 test/test_ffmpeg_frame.rb
View
23 lib/ffmpeg/frame.rb
@@ -69,11 +69,32 @@ 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)
@@ -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
View
19 test/test_ffmpeg_frame.rb
@@ -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
@@ -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
@@ -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

0 comments on commit 0e13dcb

Please sign in to comment.
Something went wrong with that request. Please try again.