Permalink
Browse files

Fix FFMPEG::Frame#data, #fill add #data=, #data_size, #linesize, #clear.

Now frames can be created from ruby.

Added FFMPEG::ImageScaler test.
  • Loading branch information...
1 parent 0e13dcb commit 80df82bda110096a7de94c0f0a25b84702e5f089 @drbrain committed Sep 8, 2009
Showing with 414 additions and 31 deletions.
  1. +147 −13 lib/ffmpeg/frame.rb
  2. +20 −11 lib/ffmpeg/image_scaler.rb
  3. +41 −0 lib/ffmpeg/test_case.rb
  4. +181 −7 test/test_ffmpeg_frame.rb
  5. +25 −0 test/test_ffmpeg_image_scaler.rb
View
160 lib/ffmpeg/frame.rb
@@ -74,17 +74,117 @@ class FFMPEG::Frame
builder.c <<-C
VALUE data() {
AVFrame *frame;
+ VALUE ary;
+ int data_size, i;
+ char *data, *ptr;
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]));
+ data_size = NUM2INT(rb_funcall(self, rb_intern("data_size"), 0));
+ ary = rb_ary_new2(4);
+
+ if (frame->data[0]) {
+ data = (char *)frame->data[0];
+ rb_ary_store(ary, 0, rb_str_new(data, data_size));
+
+ for (i = 1; i < 4; i++) {
+ ptr = (char *)frame->data[i];
+
+ if (ptr) {
+ rb_ary_store(ary, i,
+ rb_str_new(ptr, data_size + data - ptr));
+ } else {
+ rb_ary_store(ary, i, Qnil);
+ }
+
+ }
+ } else {
+ for (i = 1; i < 4; i++)
+ rb_ary_store(ary, i, Qnil);
+ }
+
+ return ary;
+ }
+ C
+
+ ##
+ # :method: data=
+
+ builder.c <<-C
+ void data_equals(VALUE input) {
+ AVFrame *frame;
+ VALUE ff_error = rb_path2class("FFMPEG::Error");
+ VALUE row;
+ int data_size, i;
+
+ input = rb_ary_to_ary(input);
+
+ if (RARRAY_LEN(input) != 4)
+ rb_raise(rb_eArgError,
+ "data must be of length 4 (was %d)", RARRAY_LEN(input));
+
+ Data_Get_Struct(self, AVFrame, frame);
+
+ if (!frame->data)
+ rb_raise(ff_error, "unfilled frame");
+
+ row = rb_ary_entry(input, 0);
+ row = rb_str_to_str(row);
+
+ data_size = NUM2INT(rb_funcall(self, rb_intern("data_size"), 0));
+
+ if (RSTRING_LEN(row) != data_size)
+ rb_raise(rb_eArgError,
+ "data size mismatch (%d expected, was %d)",
+ data_size, RSTRING_LEN(row));
+
+ memcpy(frame->data[0], RSTRING_PTR(row), RSTRING_LEN(row));
+
+ for (i = 1; i < 4; i++) {
+ if (frame->data[i]) {
+ row = rb_ary_entry(input, i);
+
+ if (NIL_P(row))
+ continue;
+
+ row = rb_str_to_str(row);
+
+ memcpy(frame->data[i], RSTRING_PTR(row),
+ data_size + frame->data[0] - frame->data[i]);
+ }
+ }
+ }
+ C
+
+ ##
+ # :method: data_size
+
+ builder.c <<-C
+ int data_size() {
+ AVPicture picture;
+ int size;
+
+ VALUE width = rb_iv_get(self, "@width");
+ VALUE height = rb_iv_get(self, "@height");
+ VALUE pix_fmt = rb_iv_get(self, "@pixel_format");
+
+ if (!FIXNUM_P(width))
+ rb_raise(rb_eRuntimeError, "invalid width, cannot size");
+ if (!FIXNUM_P(height))
+ rb_raise(rb_eRuntimeError, "invalid height, cannot size");
+ if (!FIXNUM_P(pix_fmt))
+ rb_raise(rb_eRuntimeError, "invalid pixel_format, cannot size");
+
+ size = avpicture_fill(&picture, NULL, FIX2INT(pix_fmt),
+ FIX2INT(width), FIX2INT(height));
+
+ if (size < 0)
+ rb_raise(rb_path2class("FFMPEG::Error"), "unable to get size");
+
+ return size;
}
C
@@ -105,33 +205,63 @@ class FFMPEG::Frame
C
##
+ # :method: linesize
+
+ builder.c <<-C
+ VALUE linesize() {
+ AVFrame *frame;
+ VALUE ary;
+ int i;
+
+ Data_Get_Struct(self, AVFrame, frame);
+
+ if (!frame->data)
+ return Qnil;
+
+ ary = rb_ary_new2(4);
+
+ for (i = 0; i < 4; i++) {
+ rb_ary_store(ary, i, INT2NUM(frame->linesize[i]));
+ }
+
+ return ary;
+ }
+ C
+
+ ##
# :method: fill
builder.c <<-C
VALUE fill() {
AVFrame *frame;
Data_Get_Struct(self, AVFrame, frame);
- int e;
+ int e, i;
+ VALUE width = rb_iv_get(self, "@width");
+ VALUE height = rb_iv_get(self, "@height");
VALUE pix_fmt = rb_iv_get(self, "@pixel_format");
- VALUE width = rb_iv_get(self, "@width");
- VALUE height = rb_iv_get(self, "@height");
- if (!FIXNUM_P(pix_fmt))
- rb_raise(rb_eRuntimeError, "invalid pixel_format, cannot fill");
if (!FIXNUM_P(width))
rb_raise(rb_eRuntimeError, "invalid width, cannot fill");
if (!FIXNUM_P(height))
rb_raise(rb_eRuntimeError, "invalid height, cannot fill");
+ if (!FIXNUM_P(pix_fmt))
+ rb_raise(rb_eRuntimeError, "invalid pixel_format, cannot fill");
// free data if needed
- if (frame->data[0] && frame->type == FF_BUFFER_TYPE_USER)
+ if (frame->data[0] && frame->type == FF_BUFFER_TYPE_USER) {
av_freep(frame->data[0]);
+ for (i = 0; i < 4; i++)
+ frame->data[i] = NULL;
+ for (i = 0; i < 4; i++)
+ frame->linesize[i] = 0;
+ }
+
avcodec_get_frame_defaults(frame);
frame->type = FF_BUFFER_TYPE_USER;
- e = avpicture_alloc((AVPicture*)frame, FIX2INT(pix_fmt),
+ e = avpicture_alloc((AVPicture *)frame, FIX2INT(pix_fmt),
FIX2INT(width), FIX2INT(height));
if (e != 0)
@@ -170,6 +300,10 @@ def initialize(width = nil, height = nil, pixel_format = nil)
@pixel_format = pixel_format
end
+ def clear
+ self.data = ["\000" * data_size, nil, nil, nil]
+ end
+
def type
case picture_type
when I_TYPE then :I_TYPE
View
31 lib/ffmpeg/image_scaler.rb
@@ -12,22 +12,23 @@ class FFMPEG::ImageScaler
# :singleton-method: new
builder.c_singleton <<-C
- VALUE new(VALUE origin_width, VALUE origin_height, VALUE origin_pix_fmt,
+ VALUE new(VALUE from_width, VALUE from_height, VALUE from_pix_fmt,
VALUE dest_width, VALUE dest_height, VALUE dest_pix_fmt, VALUE sws_flags)
{
struct SwsContext *sws_context;
- sws_context = sws_getContext(NUM2INT(origin_width),
- NUM2INT(origin_height),
- NUM2INT(origin_pix_fmt),
+ sws_context = sws_getContext(NUM2INT(from_width),
+ NUM2INT(from_height),
+ NUM2INT(from_pix_fmt),
NUM2INT(dest_width),
NUM2INT(dest_height),
NUM2INT(dest_pix_fmt),
NUM2INT(sws_flags), NULL, NULL, NULL);
VALUE obj = Data_Wrap_Struct(self, 0, free_sws_context, sws_context);
- rb_funcall(obj, rb_intern("initialize"), 7, origin_width, origin_height,
- origin_pix_fmt, dest_width, dest_height, dest_pix_fmt, sws_flags);
+ rb_funcall(obj, rb_intern("initialize"), 7,
+ from_width, from_height, from_pix_fmt,
+ dest_width, dest_height, dest_pix_fmt, sws_flags);
return obj;
}
@@ -58,7 +59,7 @@ class FFMPEG::ImageScaler
return rb_out_frame;
sws_scale(img_convert_ctx, in_frame->data, in_frame->linesize,
- 0, FIX2INT(rb_iv_get(self, "@origin_height")),
+ 0, FIX2INT(rb_iv_get(self, "@from_height")),
out_frame->data, out_frame->linesize);
return rb_out_frame;
@@ -69,6 +70,14 @@ class FFMPEG::ImageScaler
builder.map_c_const 'SWS_BICUBIC' => ['int', :BICUBIC]
end
+ attr_reader :from_height
+ attr_reader :from_width
+ attr_reader :from_pixel_format
+
+ attr_reader :dest_height
+ attr_reader :dest_width
+ attr_reader :dest_pixel_format
+
def self.for(decoder, encoder, type)
type = const_get type if Symbol === type
@@ -77,11 +86,11 @@ def self.for(decoder, encoder, type)
type
end
- def initialize(origin_width, origin_height, origin_pixel_format,
+ def initialize(from_width, from_height, from_pixel_format,
dest_width, dest_height, dest_pixel_format, flags)
- @origin_width = origin_width
- @origin_height = origin_height
- @origin_pixel_format = origin_pixel_format
+ @from_width = from_width
+ @from_height = from_height
+ @from_pixel_format = from_pixel_format
@dest_width = dest_width
@dest_height = dest_height
View
41 lib/ffmpeg/test_case.rb
@@ -8,5 +8,46 @@ def setup
@thumbs_up = File.expand_path 'Thumbs Up!.3gp', 'test'
end
+ ##
+ # From libavcodec/api-example.c
+
+ def util_fill_frame(frame, index = 0)
+ assert_equal FFMPEG::PixelFormat::YUV420P, frame.pixel_format,
+ 'util_fill_frame only works with YUV420P frames'
+
+ height = frame.height
+ width = frame.width
+ data = frame.data
+ linesize = frame.linesize
+
+ # Y
+ data_0 = data[0]
+ line_0 = linesize[0]
+
+ (0...height).each do |y|
+ (0...width).each do |x|
+ #p (y * line_0 + x) => (x + y + index * 3).chr
+ data_0[y * line_0 + x, 1] = (x + y + index * 3).chr
+ end
+ end
+
+ # Cb and Cr
+ data_1 = data[1]
+ line_1 = linesize[1]
+ data_2 = data[2]
+ line_2 = linesize[2]
+
+ (0...(height / 2)).each do |y|
+ (0...(width / 2)).each do |x|
+ #p (y * line_1 + x) => (128 + y + index * 2).chr
+ data_1[y * line_1 + x, 1] = (128 + y + index * 2).chr
+ #p (y * line_2 + x) => ( 64 + x + index * 5).chr
+ data_2[y * line_2 + x, 1] = ( 64 + x + index * 5).chr
+ end
+ end
+
+ data
+ end
+
end
View
188 test/test_ffmpeg_frame.rb
@@ -7,6 +7,7 @@ def setup
@frame = FFMPEG::Frame.new 40, 30, FFMPEG::PixelFormat::YUV420P
@frame.defaults
+ @data_size = @frame.data_size
end
def test_class_from
@@ -19,16 +20,181 @@ def test_class_from
assert_equal FFMPEG::PixelFormat::YUV420P, frame.pixel_format
end
+ def test_clear
+ @frame.fill
+
+ @frame.data = ["\x55" * @data_size, nil, nil, nil]
+
+ @frame.clear
+
+ assert_equal "\0" * @data_size, @frame.data[0]
+ 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
+ assert_equal 4, data.length
+ assert_equal @data_size, data[0].length
+ refute_nil data[1]
+ refute_nil data[2]
+ assert_equal nil, data[3]
+
+ data[0].replace "\xff"
+
+ refute_equal "\xff", @frame.data[0]
+ end
+
+ def test_data_equals
+ @frame.fill
+
+ @frame.data = ["\x55" * @data_size, nil, nil, nil]
+
+ assert_equal "\x55" * @data_size, @frame.data[0]
+ end
+
+ def test_data_equals2
+ @frame.fill
+
+ data = util_fill_frame @frame
+
+ @frame.data = data
+
+ data = @frame.data
+
+ expected = [
+ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
+ "\x20\x21\x22\x23\x24\x25\x26\x27\x01\x02\x03\x04\x05\x06\x07\x08",
+ "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18",
+ "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28",
+ "\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11",
+ "\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21",
+ "\x22\x23\x24\x25\x26\x27\x28\x29\x03\x04\x05\x06\x07\x08\x09\x0a",
+ "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a",
+ "\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a",
+ "\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13",
+ "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23",
+ "\x24\x25\x26\x27\x28\x29\x2a\x2b\x05\x06\x07\x08\x09\x0a\x0b\x0c",
+ "\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c",
+ "\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c",
+ "\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15",
+ "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25",
+ "\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
+ "\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e",
+ "\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e",
+ "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17",
+ "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27",
+ "\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10",
+ "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
+ "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30",
+ "\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
+ "\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29",
+ "\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x0b\x0c\x0d\x0e\x0f\x10\x11\x12",
+ "\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22",
+ "\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32",
+ "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b",
+ "\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b",
+ "\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x0d\x0e\x0f\x10\x11\x12\x13\x14",
+ "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24",
+ "\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34",
+ "\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
+ "\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d",
+ "\x2e\x2f\x30\x31\x32\x33\x34\x35\x0f\x10\x11\x12\x13\x14\x15\x16",
+ "\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26",
+ "\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36",
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
+ "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
+ "\x30\x31\x32\x33\x34\x35\x36\x37\x11\x12\x13\x14\x15\x16\x17\x18",
+ "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28",
+ "\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38",
+ "\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21",
+ "\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31",
+ "\x32\x33\x34\x35\x36\x37\x38\x39\x13\x14\x15\x16\x17\x18\x19\x1a",
+ "\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a",
+ "\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a",
+ "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23",
+ "\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33",
+ "\x34\x35\x36\x37\x38\x39\x3a\x3b\x15\x16\x17\x18\x19\x1a\x1b\x1c",
+ "\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c",
+ "\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c",
+ "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25",
+ "\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35",
+ "\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x17\x18\x19\x1a\x1b\x1c\x1d\x1e",
+ "\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e",
+ "\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e",
+ "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27",
+ "\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37",
+ "\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
+ "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30",
+ "\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40",
+ "\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29",
+ "\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39",
+ "\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x1b\x1c\x1d\x1e\x1f\x20\x21\x22",
+ "\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32",
+ "\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42",
+ "\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b",
+ "\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b",
+ "\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x1d\x1e\x1f\x20\x21\x22\x23\x24",
+ "\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34",
+ "\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44",
+ "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
+ "\x80\x80\x80\x80\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81",
+ "\x81\x81\x81\x81\x81\x81\x81\x81\x82\x82\x82\x82\x82\x82\x82\x82",
+ "\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x83\x83\x83\x83",
+ "\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83",
+ "\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84",
+ "\x84\x84\x84\x84\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85",
+ "\x85\x85\x85\x85\x85\x85\x85\x85\x86\x86\x86\x86\x86\x86\x86\x86",
+ "\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x87\x87\x87\x87",
+ "\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87",
+ "\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88",
+ "\x88\x88\x88\x88\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89",
+ "\x89\x89\x89\x89\x89\x89\x89\x89\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a",
+ "\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8b\x8b\x8b\x8b",
+ "\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b",
+ "\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c",
+ "\x8c\x8c\x8c\x8c\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d",
+ "\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e",
+ "\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x40\x41\x42\x43",
+ "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
+ "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
+ "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
+ "\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
+ "\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
+ "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
+ "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
+ "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
+ "\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
+ "\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
+ "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
+ "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
+ "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
+ "\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
+ "\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
+ "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
+ "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
+ "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
+ "\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
+ ].join ''
+
+ # for rebuilding above if it's wrong
+ #data = data.first
+
+ #until data.empty? do
+ # bytes = data.slice! 0, 16
+ # p bytes.unpack('C*').map { |byte|
+ # "x#{"%02x" % byte}"
+ # }.join('')
+ #end
+
+ #flunk
+ assert_equal expected, data[0]
+ end
+
+ def test_data_size
+ assert_equal 1800, @data_size
end
def test_defaults
@@ -40,11 +206,13 @@ def test_defaults
end
def test_fill
- assert_equal [ 0, 0, 0, 0], @frame.data.map { |d| d.length }
+ assert_equal [nil, nil, nil, nil], @frame.data
@frame.fill
- assert_equal [40, 20, 20, 0], @frame.data.map { |d| d.length }
+ data = @frame.data
+
+ assert_equal @data_size, data.first.length
end
def test_key_frame
@@ -55,6 +223,12 @@ def test_key_frame_eh
assert @frame.key_frame?
end
+ def test_linesize
+ @frame.fill
+
+ assert_equal [40, 20, 20, 0], @frame.linesize
+ end
+
def test_picture_type
@frame.picture_type = FFMPEG::PixelFormat::RGBA
assert_equal FFMPEG::PixelFormat::RGBA, @frame.picture_type
View
25 test/test_ffmpeg_image_scaler.rb
@@ -0,0 +1,25 @@
+require 'ffmpeg/test_case'
+
+class TestFFMPEGImageScaler < FFMPEG::TestCase
+
+ def setup
+ super
+
+ @s = FFMPEG::ImageScaler.new 40, 30, FFMPEG::PixelFormat::YUV420P,
+ 80, 60, FFMPEG::PixelFormat::YUV420P,
+ FFMPEG::ImageScaler::BICUBIC
+ end
+
+ def test_scale
+ from = FFMPEG::Frame.new @s.from_height, @s.from_width, @s.from_pixel_format
+ from.fill
+
+ util_fill_frame from
+
+ dest = @s.scale from
+
+ assert_equal from.data_size * 4, dest.data_size
+ end
+
+end
+

0 comments on commit 80df82b

Please sign in to comment.