Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 80df82bda110096a7de94c0f0a25b84702e5f089 1 parent 0e13dcb
Eric Hodel authored
160 lib/ffmpeg/frame.rb
@@ -74,17 +74,117 @@ class FFMPEG::Frame
74 74 builder.c <<-C
75 75 VALUE data() {
76 76 AVFrame *frame;
  77 + VALUE ary;
  78 + int data_size, i;
  79 + char *data, *ptr;
77 80
78 81 Data_Get_Struct(self, AVFrame, frame);
79   -
  82 +
80 83 if (!frame->data)
81 84 return Qnil;
82 85
83   - return rb_ary_new3(4,
84   - rb_str_new((char *)frame->data[0], frame->linesize[0]),
85   - rb_str_new((char *)frame->data[1], frame->linesize[1]),
86   - rb_str_new((char *)frame->data[2], frame->linesize[2]),
87   - rb_str_new((char *)frame->data[3], frame->linesize[3]));
  86 + data_size = NUM2INT(rb_funcall(self, rb_intern("data_size"), 0));
  87 + ary = rb_ary_new2(4);
  88 +
  89 + if (frame->data[0]) {
  90 + data = (char *)frame->data[0];
  91 + rb_ary_store(ary, 0, rb_str_new(data, data_size));
  92 +
  93 + for (i = 1; i < 4; i++) {
  94 + ptr = (char *)frame->data[i];
  95 +
  96 + if (ptr) {
  97 + rb_ary_store(ary, i,
  98 + rb_str_new(ptr, data_size + data - ptr));
  99 + } else {
  100 + rb_ary_store(ary, i, Qnil);
  101 + }
  102 +
  103 + }
  104 + } else {
  105 + for (i = 1; i < 4; i++)
  106 + rb_ary_store(ary, i, Qnil);
  107 + }
  108 +
  109 + return ary;
  110 + }
  111 + C
  112 +
  113 + ##
  114 + # :method: data=
  115 +
  116 + builder.c <<-C
  117 + void data_equals(VALUE input) {
  118 + AVFrame *frame;
  119 + VALUE ff_error = rb_path2class("FFMPEG::Error");
  120 + VALUE row;
  121 + int data_size, i;
  122 +
  123 + input = rb_ary_to_ary(input);
  124 +
  125 + if (RARRAY_LEN(input) != 4)
  126 + rb_raise(rb_eArgError,
  127 + "data must be of length 4 (was %d)", RARRAY_LEN(input));
  128 +
  129 + Data_Get_Struct(self, AVFrame, frame);
  130 +
  131 + if (!frame->data)
  132 + rb_raise(ff_error, "unfilled frame");
  133 +
  134 + row = rb_ary_entry(input, 0);
  135 + row = rb_str_to_str(row);
  136 +
  137 + data_size = NUM2INT(rb_funcall(self, rb_intern("data_size"), 0));
  138 +
  139 + if (RSTRING_LEN(row) != data_size)
  140 + rb_raise(rb_eArgError,
  141 + "data size mismatch (%d expected, was %d)",
  142 + data_size, RSTRING_LEN(row));
  143 +
  144 + memcpy(frame->data[0], RSTRING_PTR(row), RSTRING_LEN(row));
  145 +
  146 + for (i = 1; i < 4; i++) {
  147 + if (frame->data[i]) {
  148 + row = rb_ary_entry(input, i);
  149 +
  150 + if (NIL_P(row))
  151 + continue;
  152 +
  153 + row = rb_str_to_str(row);
  154 +
  155 + memcpy(frame->data[i], RSTRING_PTR(row),
  156 + data_size + frame->data[0] - frame->data[i]);
  157 + }
  158 + }
  159 + }
  160 + C
  161 +
  162 + ##
  163 + # :method: data_size
  164 +
  165 + builder.c <<-C
  166 + int data_size() {
  167 + AVPicture picture;
  168 + int size;
  169 +
  170 + VALUE width = rb_iv_get(self, "@width");
  171 + VALUE height = rb_iv_get(self, "@height");
  172 + VALUE pix_fmt = rb_iv_get(self, "@pixel_format");
  173 +
  174 + if (!FIXNUM_P(width))
  175 + rb_raise(rb_eRuntimeError, "invalid width, cannot size");
  176 + if (!FIXNUM_P(height))
  177 + rb_raise(rb_eRuntimeError, "invalid height, cannot size");
  178 + if (!FIXNUM_P(pix_fmt))
  179 + rb_raise(rb_eRuntimeError, "invalid pixel_format, cannot size");
  180 +
  181 + size = avpicture_fill(&picture, NULL, FIX2INT(pix_fmt),
  182 + FIX2INT(width), FIX2INT(height));
  183 +
  184 + if (size < 0)
  185 + rb_raise(rb_path2class("FFMPEG::Error"), "unable to get size");
  186 +
  187 + return size;
88 188 }
89 189 C
90 190
@@ -105,33 +205,63 @@ class FFMPEG::Frame
105 205 C
106 206
107 207 ##
  208 + # :method: linesize
  209 +
  210 + builder.c <<-C
  211 + VALUE linesize() {
  212 + AVFrame *frame;
  213 + VALUE ary;
  214 + int i;
  215 +
  216 + Data_Get_Struct(self, AVFrame, frame);
  217 +
  218 + if (!frame->data)
  219 + return Qnil;
  220 +
  221 + ary = rb_ary_new2(4);
  222 +
  223 + for (i = 0; i < 4; i++) {
  224 + rb_ary_store(ary, i, INT2NUM(frame->linesize[i]));
  225 + }
  226 +
  227 + return ary;
  228 + }
  229 + C
  230 +
  231 + ##
108 232 # :method: fill
109 233
110 234 builder.c <<-C
111 235 VALUE fill() {
112 236 AVFrame *frame;
113 237 Data_Get_Struct(self, AVFrame, frame);
114   - int e;
  238 + int e, i;
115 239
  240 + VALUE width = rb_iv_get(self, "@width");
  241 + VALUE height = rb_iv_get(self, "@height");
116 242 VALUE pix_fmt = rb_iv_get(self, "@pixel_format");
117   - VALUE width = rb_iv_get(self, "@width");
118   - VALUE height = rb_iv_get(self, "@height");
119 243
120   - if (!FIXNUM_P(pix_fmt))
121   - rb_raise(rb_eRuntimeError, "invalid pixel_format, cannot fill");
122 244 if (!FIXNUM_P(width))
123 245 rb_raise(rb_eRuntimeError, "invalid width, cannot fill");
124 246 if (!FIXNUM_P(height))
125 247 rb_raise(rb_eRuntimeError, "invalid height, cannot fill");
  248 + if (!FIXNUM_P(pix_fmt))
  249 + rb_raise(rb_eRuntimeError, "invalid pixel_format, cannot fill");
126 250
127 251 // free data if needed
128   - if (frame->data[0] && frame->type == FF_BUFFER_TYPE_USER)
  252 + if (frame->data[0] && frame->type == FF_BUFFER_TYPE_USER) {
129 253 av_freep(frame->data[0]);
130 254
  255 + for (i = 0; i < 4; i++)
  256 + frame->data[i] = NULL;
  257 + for (i = 0; i < 4; i++)
  258 + frame->linesize[i] = 0;
  259 + }
  260 +
131 261 avcodec_get_frame_defaults(frame);
132 262 frame->type = FF_BUFFER_TYPE_USER;
133 263
134   - e = avpicture_alloc((AVPicture*)frame, FIX2INT(pix_fmt),
  264 + e = avpicture_alloc((AVPicture *)frame, FIX2INT(pix_fmt),
135 265 FIX2INT(width), FIX2INT(height));
136 266
137 267 if (e != 0)
@@ -170,6 +300,10 @@ def initialize(width = nil, height = nil, pixel_format = nil)
170 300 @pixel_format = pixel_format
171 301 end
172 302
  303 + def clear
  304 + self.data = ["\000" * data_size, nil, nil, nil]
  305 + end
  306 +
173 307 def type
174 308 case picture_type
175 309 when I_TYPE then :I_TYPE
31 lib/ffmpeg/image_scaler.rb
@@ -12,13 +12,13 @@ class FFMPEG::ImageScaler
12 12 # :singleton-method: new
13 13
14 14 builder.c_singleton <<-C
15   - VALUE new(VALUE origin_width, VALUE origin_height, VALUE origin_pix_fmt,
  15 + VALUE new(VALUE from_width, VALUE from_height, VALUE from_pix_fmt,
16 16 VALUE dest_width, VALUE dest_height, VALUE dest_pix_fmt, VALUE sws_flags)
17 17 {
18 18 struct SwsContext *sws_context;
19   - sws_context = sws_getContext(NUM2INT(origin_width),
20   - NUM2INT(origin_height),
21   - NUM2INT(origin_pix_fmt),
  19 + sws_context = sws_getContext(NUM2INT(from_width),
  20 + NUM2INT(from_height),
  21 + NUM2INT(from_pix_fmt),
22 22 NUM2INT(dest_width),
23 23 NUM2INT(dest_height),
24 24 NUM2INT(dest_pix_fmt),
@@ -26,8 +26,9 @@ class FFMPEG::ImageScaler
26 26
27 27 VALUE obj = Data_Wrap_Struct(self, 0, free_sws_context, sws_context);
28 28
29   - rb_funcall(obj, rb_intern("initialize"), 7, origin_width, origin_height,
30   - origin_pix_fmt, dest_width, dest_height, dest_pix_fmt, sws_flags);
  29 + rb_funcall(obj, rb_intern("initialize"), 7,
  30 + from_width, from_height, from_pix_fmt,
  31 + dest_width, dest_height, dest_pix_fmt, sws_flags);
31 32
32 33 return obj;
33 34 }
@@ -58,7 +59,7 @@ class FFMPEG::ImageScaler
58 59 return rb_out_frame;
59 60
60 61 sws_scale(img_convert_ctx, in_frame->data, in_frame->linesize,
61   - 0, FIX2INT(rb_iv_get(self, "@origin_height")),
  62 + 0, FIX2INT(rb_iv_get(self, "@from_height")),
62 63 out_frame->data, out_frame->linesize);
63 64
64 65 return rb_out_frame;
@@ -69,6 +70,14 @@ class FFMPEG::ImageScaler
69 70 builder.map_c_const 'SWS_BICUBIC' => ['int', :BICUBIC]
70 71 end
71 72
  73 + attr_reader :from_height
  74 + attr_reader :from_width
  75 + attr_reader :from_pixel_format
  76 +
  77 + attr_reader :dest_height
  78 + attr_reader :dest_width
  79 + attr_reader :dest_pixel_format
  80 +
72 81 def self.for(decoder, encoder, type)
73 82 type = const_get type if Symbol === type
74 83
@@ -77,11 +86,11 @@ def self.for(decoder, encoder, type)
77 86 type
78 87 end
79 88
80   - def initialize(origin_width, origin_height, origin_pixel_format,
  89 + def initialize(from_width, from_height, from_pixel_format,
81 90 dest_width, dest_height, dest_pixel_format, flags)
82   - @origin_width = origin_width
83   - @origin_height = origin_height
84   - @origin_pixel_format = origin_pixel_format
  91 + @from_width = from_width
  92 + @from_height = from_height
  93 + @from_pixel_format = from_pixel_format
85 94
86 95 @dest_width = dest_width
87 96 @dest_height = dest_height
41 lib/ffmpeg/test_case.rb
@@ -8,5 +8,46 @@ def setup
8 8 @thumbs_up = File.expand_path 'Thumbs Up!.3gp', 'test'
9 9 end
10 10
  11 + ##
  12 + # From libavcodec/api-example.c
  13 +
  14 + def util_fill_frame(frame, index = 0)
  15 + assert_equal FFMPEG::PixelFormat::YUV420P, frame.pixel_format,
  16 + 'util_fill_frame only works with YUV420P frames'
  17 +
  18 + height = frame.height
  19 + width = frame.width
  20 + data = frame.data
  21 + linesize = frame.linesize
  22 +
  23 + # Y
  24 + data_0 = data[0]
  25 + line_0 = linesize[0]
  26 +
  27 + (0...height).each do |y|
  28 + (0...width).each do |x|
  29 + #p (y * line_0 + x) => (x + y + index * 3).chr
  30 + data_0[y * line_0 + x, 1] = (x + y + index * 3).chr
  31 + end
  32 + end
  33 +
  34 + # Cb and Cr
  35 + data_1 = data[1]
  36 + line_1 = linesize[1]
  37 + data_2 = data[2]
  38 + line_2 = linesize[2]
  39 +
  40 + (0...(height / 2)).each do |y|
  41 + (0...(width / 2)).each do |x|
  42 + #p (y * line_1 + x) => (128 + y + index * 2).chr
  43 + data_1[y * line_1 + x, 1] = (128 + y + index * 2).chr
  44 + #p (y * line_2 + x) => ( 64 + x + index * 5).chr
  45 + data_2[y * line_2 + x, 1] = ( 64 + x + index * 5).chr
  46 + end
  47 + end
  48 +
  49 + data
  50 + end
  51 +
11 52 end
12 53
188 test/test_ffmpeg_frame.rb
@@ -7,6 +7,7 @@ def setup
7 7
8 8 @frame = FFMPEG::Frame.new 40, 30, FFMPEG::PixelFormat::YUV420P
9 9 @frame.defaults
  10 + @data_size = @frame.data_size
10 11 end
11 12
12 13 def test_class_from
@@ -19,16 +20,181 @@ def test_class_from
19 20 assert_equal FFMPEG::PixelFormat::YUV420P, frame.pixel_format
20 21 end
21 22
  23 + def test_clear
  24 + @frame.fill
  25 +
  26 + @frame.data = ["\x55" * @data_size, nil, nil, nil]
  27 +
  28 + @frame.clear
  29 +
  30 + assert_equal "\0" * @data_size, @frame.data[0]
  31 + end
  32 +
22 33 def test_data
23 34 @frame.fill
24 35
25 36 data = @frame.data
26 37
27   - assert_equal 4, data.length
28   - assert_equal 40, data[0].length
29   - assert_equal 20, data[1].length
30   - assert_equal 20, data[2].length
31   - assert_equal 0, data[3].length
  38 + assert_equal 4, data.length
  39 + assert_equal @data_size, data[0].length
  40 + refute_nil data[1]
  41 + refute_nil data[2]
  42 + assert_equal nil, data[3]
  43 +
  44 + data[0].replace "\xff"
  45 +
  46 + refute_equal "\xff", @frame.data[0]
  47 + end
  48 +
  49 + def test_data_equals
  50 + @frame.fill
  51 +
  52 + @frame.data = ["\x55" * @data_size, nil, nil, nil]
  53 +
  54 + assert_equal "\x55" * @data_size, @frame.data[0]
  55 + end
  56 +
  57 + def test_data_equals2
  58 + @frame.fill
  59 +
  60 + data = util_fill_frame @frame
  61 +
  62 + @frame.data = data
  63 +
  64 + data = @frame.data
  65 +
  66 + expected = [
  67 + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
  68 + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
  69 + "\x20\x21\x22\x23\x24\x25\x26\x27\x01\x02\x03\x04\x05\x06\x07\x08",
  70 + "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18",
  71 + "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28",
  72 + "\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11",
  73 + "\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21",
  74 + "\x22\x23\x24\x25\x26\x27\x28\x29\x03\x04\x05\x06\x07\x08\x09\x0a",
  75 + "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a",
  76 + "\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a",
  77 + "\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13",
  78 + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23",
  79 + "\x24\x25\x26\x27\x28\x29\x2a\x2b\x05\x06\x07\x08\x09\x0a\x0b\x0c",
  80 + "\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c",
  81 + "\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c",
  82 + "\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15",
  83 + "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25",
  84 + "\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
  85 + "\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e",
  86 + "\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e",
  87 + "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17",
  88 + "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27",
  89 + "\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10",
  90 + "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
  91 + "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30",
  92 + "\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
  93 + "\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29",
  94 + "\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x0b\x0c\x0d\x0e\x0f\x10\x11\x12",
  95 + "\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22",
  96 + "\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32",
  97 + "\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b",
  98 + "\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b",
  99 + "\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x0d\x0e\x0f\x10\x11\x12\x13\x14",
  100 + "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24",
  101 + "\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34",
  102 + "\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
  103 + "\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d",
  104 + "\x2e\x2f\x30\x31\x32\x33\x34\x35\x0f\x10\x11\x12\x13\x14\x15\x16",
  105 + "\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26",
  106 + "\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36",
  107 + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
  108 + "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
  109 + "\x30\x31\x32\x33\x34\x35\x36\x37\x11\x12\x13\x14\x15\x16\x17\x18",
  110 + "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28",
  111 + "\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38",
  112 + "\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21",
  113 + "\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31",
  114 + "\x32\x33\x34\x35\x36\x37\x38\x39\x13\x14\x15\x16\x17\x18\x19\x1a",
  115 + "\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a",
  116 + "\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a",
  117 + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23",
  118 + "\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33",
  119 + "\x34\x35\x36\x37\x38\x39\x3a\x3b\x15\x16\x17\x18\x19\x1a\x1b\x1c",
  120 + "\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c",
  121 + "\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c",
  122 + "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25",
  123 + "\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35",
  124 + "\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x17\x18\x19\x1a\x1b\x1c\x1d\x1e",
  125 + "\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e",
  126 + "\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e",
  127 + "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27",
  128 + "\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37",
  129 + "\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
  130 + "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30",
  131 + "\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40",
  132 + "\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29",
  133 + "\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39",
  134 + "\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x1b\x1c\x1d\x1e\x1f\x20\x21\x22",
  135 + "\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32",
  136 + "\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42",
  137 + "\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b",
  138 + "\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b",
  139 + "\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x1d\x1e\x1f\x20\x21\x22\x23\x24",
  140 + "\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34",
  141 + "\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44",
  142 + "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
  143 + "\x80\x80\x80\x80\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81",
  144 + "\x81\x81\x81\x81\x81\x81\x81\x81\x82\x82\x82\x82\x82\x82\x82\x82",
  145 + "\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x83\x83\x83\x83",
  146 + "\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83",
  147 + "\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84",
  148 + "\x84\x84\x84\x84\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85",
  149 + "\x85\x85\x85\x85\x85\x85\x85\x85\x86\x86\x86\x86\x86\x86\x86\x86",
  150 + "\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x87\x87\x87\x87",
  151 + "\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87",
  152 + "\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88",
  153 + "\x88\x88\x88\x88\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89",
  154 + "\x89\x89\x89\x89\x89\x89\x89\x89\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a",
  155 + "\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8b\x8b\x8b\x8b",
  156 + "\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b",
  157 + "\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c",
  158 + "\x8c\x8c\x8c\x8c\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d",
  159 + "\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e",
  160 + "\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x40\x41\x42\x43",
  161 + "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
  162 + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
  163 + "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
  164 + "\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
  165 + "\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
  166 + "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
  167 + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
  168 + "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
  169 + "\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
  170 + "\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
  171 + "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
  172 + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
  173 + "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
  174 + "\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
  175 + "\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
  176 + "\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
  177 + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
  178 + "\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
  179 + "\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
  180 + ].join ''
  181 +
  182 + # for rebuilding above if it's wrong
  183 + #data = data.first
  184 +
  185 + #until data.empty? do
  186 + # bytes = data.slice! 0, 16
  187 + # p bytes.unpack('C*').map { |byte|
  188 + # "x#{"%02x" % byte}"
  189 + # }.join('')
  190 + #end
  191 +
  192 + #flunk
  193 + assert_equal expected, data[0]
  194 + end
  195 +
  196 + def test_data_size
  197 + assert_equal 1800, @data_size
32 198 end
33 199
34 200 def test_defaults
@@ -40,11 +206,13 @@ def test_defaults
40 206 end
41 207
42 208 def test_fill
43   - assert_equal [ 0, 0, 0, 0], @frame.data.map { |d| d.length }
  209 + assert_equal [nil, nil, nil, nil], @frame.data
44 210
45 211 @frame.fill
46 212
47   - assert_equal [40, 20, 20, 0], @frame.data.map { |d| d.length }
  213 + data = @frame.data
  214 +
  215 + assert_equal @data_size, data.first.length
48 216 end
49 217
50 218 def test_key_frame
@@ -55,6 +223,12 @@ def test_key_frame_eh
55 223 assert @frame.key_frame?
56 224 end
57 225
  226 + def test_linesize
  227 + @frame.fill
  228 +
  229 + assert_equal [40, 20, 20, 0], @frame.linesize
  230 + end
  231 +
58 232 def test_picture_type
59 233 @frame.picture_type = FFMPEG::PixelFormat::RGBA
60 234 assert_equal FFMPEG::PixelFormat::RGBA, @frame.picture_type
25 test/test_ffmpeg_image_scaler.rb
... ... @@ -0,0 +1,25 @@
  1 +require 'ffmpeg/test_case'
  2 +
  3 +class TestFFMPEGImageScaler < FFMPEG::TestCase
  4 +
  5 + def setup
  6 + super
  7 +
  8 + @s = FFMPEG::ImageScaler.new 40, 30, FFMPEG::PixelFormat::YUV420P,
  9 + 80, 60, FFMPEG::PixelFormat::YUV420P,
  10 + FFMPEG::ImageScaler::BICUBIC
  11 + end
  12 +
  13 + def test_scale
  14 + from = FFMPEG::Frame.new @s.from_height, @s.from_width, @s.from_pixel_format
  15 + from.fill
  16 +
  17 + util_fill_frame from
  18 +
  19 + dest = @s.scale from
  20 +
  21 + assert_equal from.data_size * 4, dest.data_size
  22 + end
  23 +
  24 +end
  25 +

0 comments on commit 80df82b

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