1 /* GStreamer video frame cropping
2 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:element-videocrop
22 * @see_also: #GstVideoBox
24 * This element crops video frames, meaning it can remove parts of the
25 * picture on the left, right, top or bottom of the picture and output
26 * a smaller picture than the input picture, with the unwanted parts at the
29 * The videocrop element is similar to the videobox element, but its main
30 * goal is to support a multitude of formats as efficiently as possible.
31 * Unlike videbox, it cannot add borders to the picture and unlike videbox
32 * it will always output images in exactly the same format as the input image.
34 * If there is nothing to crop, the element will operate in pass-through mode.
36 * Note that no special efforts are made to handle chroma-subsampled formats
37 * in the case of odd-valued cropping and compensate for sub-unit chroma plane
38 * shifts for such formats in the case where the #GstVideoCrop:left or
39 * #GstVideoCrop:top property is set to an odd number. This doesn't matter for
40 * most use cases, but it might matter for yours.
43 * <title>Example launch line</title>
45 * gst-launch -v videotestsrc ! videocrop top=42 left=1 right=4 bottom=0 ! ximagesink
51 * - for packed formats, we could avoid memcpy() in case crop_left
52 * and crop_right are 0 and just create a sub-buffer of the input
61 #include <gst/video/video.h>
63 #include "gstvideocrop.h"
64 #include "gstaspectratiocrop.h"
68 GST_DEBUG_CATEGORY_STATIC (videocrop_debug);
69 #define GST_CAT_DEFAULT videocrop_debug
80 #define VIDEO_CROP_CAPS \
81 GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR, " \
82 "RGBA, ARGB, BGRA, ABGR, RGB, BGR, AYUV, YUY2, " \
83 "YVYU, UYVY, Y800, I420, RGB16, RGB15, GRAY8 }")
85 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
88 GST_STATIC_CAPS (VIDEO_CROP_CAPS)
91 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
94 GST_STATIC_CAPS (VIDEO_CROP_CAPS)
97 #define gst_video_crop_parent_class parent_class
98 G_DEFINE_TYPE (GstVideoCrop, gst_video_crop, GST_TYPE_BASE_TRANSFORM);
100 static void gst_video_crop_set_property (GObject * object, guint prop_id,
101 const GValue * value, GParamSpec * pspec);
102 static void gst_video_crop_get_property (GObject * object, guint prop_id,
103 GValue * value, GParamSpec * pspec);
105 static GstCaps *gst_video_crop_transform_caps (GstBaseTransform * trans,
106 GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps);
107 static GstFlowReturn gst_video_crop_transform (GstBaseTransform * trans,
108 GstBuffer * inbuf, GstBuffer * outbuf);
109 static gboolean gst_video_crop_get_unit_size (GstBaseTransform * trans,
110 GstCaps * caps, guint * size);
111 static gboolean gst_video_crop_set_caps (GstBaseTransform * trans,
112 GstCaps * in_caps, GstCaps * outcaps);
113 static gboolean gst_video_crop_src_event (GstBaseTransform * trans,
117 gst_video_crop_src_event (GstBaseTransform * trans, GstEvent * event)
120 GstStructure *new_structure;
121 const GstStructure *structure;
122 const gchar *event_name;
126 GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
129 GST_OBJECT_LOCK (vcrop);
130 if (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION &&
131 (vcrop->crop_left != 0 || vcrop->crop_top != 0)) {
132 structure = gst_event_get_structure (event);
133 event_name = gst_structure_get_string (structure, "event");
136 (strcmp (event_name, "mouse-move") == 0 ||
137 strcmp (event_name, "mouse-button-press") == 0 ||
138 strcmp (event_name, "mouse-button-release") == 0)) {
140 if (gst_structure_get_double (structure, "pointer_x", &pointer_x) &&
141 gst_structure_get_double (structure, "pointer_y", &pointer_y)) {
143 new_structure = gst_structure_copy (structure);
144 gst_structure_set (new_structure,
145 "pointer_x", G_TYPE_DOUBLE, (double) (pointer_x + vcrop->crop_left),
146 "pointer_y", G_TYPE_DOUBLE, (double) (pointer_y + vcrop->crop_top),
149 new_event = gst_event_new_navigation (new_structure);
150 gst_event_unref (event);
152 GST_WARNING_OBJECT (vcrop, "Failed to read navigation event");
157 GST_OBJECT_UNLOCK (vcrop);
158 return GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans,
159 (new_event ? new_event : event));
163 gst_video_crop_class_init (GstVideoCropClass * klass)
165 GObjectClass *gobject_class;
166 GstElementClass *element_class;
167 GstBaseTransformClass *basetransform_class;
169 gobject_class = (GObjectClass *) klass;
170 element_class = (GstElementClass *) klass;
171 basetransform_class = (GstBaseTransformClass *) klass;
173 gst_element_class_set_details_simple (element_class, "Crop",
174 "Filter/Effect/Video",
175 "Crops video into a user-defined region",
176 "Tim-Philipp Müller <tim centricular net>");
178 gst_element_class_add_pad_template (element_class,
179 gst_static_pad_template_get (&sink_template));
180 gst_element_class_add_pad_template (element_class,
181 gst_static_pad_template_get (&src_template));
182 gst_element_class_set_details_simple (element_class, "Crop",
183 "Filter/Effect/Video",
184 "Crops video into a user-defined region",
185 "Tim-Philipp Müller <tim centricular net>");
187 gst_element_class_add_pad_template (element_class,
188 gst_static_pad_template_get (&sink_template));
189 gst_element_class_add_pad_template (element_class,
190 gst_static_pad_template_get (&src_template));
192 gobject_class->set_property = gst_video_crop_set_property;
193 gobject_class->get_property = gst_video_crop_get_property;
195 g_object_class_install_property (gobject_class, ARG_LEFT,
196 g_param_spec_int ("left", "Left", "Pixels to crop at left",
197 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
198 g_object_class_install_property (gobject_class, ARG_RIGHT,
199 g_param_spec_int ("right", "Right", "Pixels to crop at right",
200 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
201 g_object_class_install_property (gobject_class, ARG_TOP,
202 g_param_spec_int ("top", "Top", "Pixels to crop at top",
203 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
204 g_object_class_install_property (gobject_class, ARG_BOTTOM,
205 g_param_spec_int ("bottom", "Bottom", "Pixels to crop at bottom",
206 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
208 basetransform_class->transform = GST_DEBUG_FUNCPTR (gst_video_crop_transform);
209 basetransform_class->transform_caps =
210 GST_DEBUG_FUNCPTR (gst_video_crop_transform_caps);
211 basetransform_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_crop_set_caps);
212 basetransform_class->get_unit_size =
213 GST_DEBUG_FUNCPTR (gst_video_crop_get_unit_size);
215 basetransform_class->passthrough_on_same_caps = FALSE;
216 basetransform_class->src_event = GST_DEBUG_FUNCPTR (gst_video_crop_src_event);
220 gst_video_crop_init (GstVideoCrop * vcrop)
222 vcrop->crop_right = 0;
223 vcrop->crop_left = 0;
225 vcrop->crop_bottom = 0;
229 gst_video_crop_get_image_details_from_caps (GstVideoCrop * vcrop,
230 GstVideoCropImageDetails * details, GstCaps * caps)
232 gst_video_info_init (&details->info);
233 if (!gst_video_info_from_caps (&details->info, caps)) {
234 goto incomplete_format;
237 if (details->info.width == 0 && details->info.height == 0) {
238 goto incomplete_format;
241 if (GST_VIDEO_INFO_IS_RGB (&details->info)
242 || GST_VIDEO_INFO_IS_GRAY (&details->info)) {
243 details->packing = VIDEO_CROP_PIXEL_FORMAT_PACKED_SIMPLE;
245 switch (GST_VIDEO_INFO_FORMAT (&details->info)) {
246 case GST_VIDEO_FORMAT_AYUV:
247 details->packing = VIDEO_CROP_PIXEL_FORMAT_PACKED_SIMPLE;
249 case GST_VIDEO_FORMAT_YVYU:
250 case GST_VIDEO_FORMAT_YUY2:
251 case GST_VIDEO_FORMAT_UYVY:
252 details->packing = VIDEO_CROP_PIXEL_FORMAT_PACKED_COMPLEX;
253 if (GST_VIDEO_INFO_FORMAT (&details->info) == GST_VIDEO_FORMAT_UYVY) {
254 /* UYVY = 4:2:2 - [U0 Y0 V0 Y1] [U2 Y2 V2 Y3] [U4 Y4 V4 Y5] */
255 details->macro_y_off = 1;
257 /* YUYV = 4:2:2 - [Y0 U0 Y1 V0] [Y2 U2 Y3 V2] [Y4 U4 Y5 V4] = YUY2 */
258 details->macro_y_off = 0;
261 case GST_VIDEO_FORMAT_Y800:
262 details->packing = VIDEO_CROP_PIXEL_FORMAT_PACKED_SIMPLE;
264 case GST_VIDEO_FORMAT_I420:
265 case GST_VIDEO_FORMAT_YV12:
266 details->packing = VIDEO_CROP_PIXEL_FORMAT_PLANAR;
278 GST_ELEMENT_ERROR (vcrop, STREAM, NOT_IMPLEMENTED, (NULL),
279 ("Unsupported format"));
285 GST_ELEMENT_ERROR (vcrop, CORE, NEGOTIATION, (NULL),
286 ("Incomplete caps, some required field is missing"));
292 gst_video_crop_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
295 GstVideoCropImageDetails img_details = { 0, };
296 GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
298 if (!gst_video_crop_get_image_details_from_caps (vcrop, &img_details, caps))
301 *size = GST_VIDEO_INFO_SIZE (&img_details.info);
305 #define ROUND_DOWN_2(n) ((n)&(~1))
308 gst_video_crop_transform_packed_complex (GstVideoCrop * vcrop,
309 GstBuffer * inbuf, GstBuffer * outbuf)
311 guint8 *in_data, *out_data;
312 gpointer in_bufdata, out_bufdata;
313 gsize insize, outsize;
318 in_bufdata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
319 out_bufdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE);
321 in_data = in_bufdata;
322 out_data = out_bufdata;
324 in_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 0);
325 out_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 0);
327 in_data += vcrop->crop_top * in_stride;
329 /* rounding down here so we end up at the start of a macro-pixel and not
330 * in the middle of one */
332 ROUND_DOWN_2 (vcrop->crop_left) *
333 GST_VIDEO_INFO_COMP_PSTRIDE (&vcrop->in.info, 0);
335 dx = GST_VIDEO_INFO_WIDTH (&vcrop->out.info) *
336 GST_VIDEO_INFO_COMP_PSTRIDE (&vcrop->out.info, 0);
338 /* UYVY = 4:2:2 - [U0 Y0 V0 Y1] [U2 Y2 V2 Y3] [U4 Y4 V4 Y5]
339 * YUYV = 4:2:2 - [Y0 U0 Y1 V0] [Y2 U2 Y3 V2] [Y4 U4 Y5 V4] = YUY2 */
340 if ((vcrop->crop_left % 2) != 0) {
341 for (i = 0; i < GST_VIDEO_INFO_HEIGHT (&vcrop->out.info); ++i) {
344 memcpy (out_data, in_data, dx);
346 /* move just the Y samples one pixel to the left, don't worry about
348 for (j = vcrop->in.macro_y_off; j < out_stride - 2; j += 2)
349 out_data[j] = in_data[j + 2];
351 in_data += in_stride;
352 out_data += out_stride;
355 for (i = 0; i < GST_VIDEO_INFO_HEIGHT (&vcrop->out.info); ++i) {
356 memcpy (out_data, in_data, dx);
357 in_data += in_stride;
358 out_data += out_stride;
361 gst_buffer_unmap (inbuf, in_bufdata, insize);
362 gst_buffer_unmap (outbuf, out_bufdata, outsize);
366 gst_video_crop_transform_packed_simple (GstVideoCrop * vcrop,
367 GstBuffer * inbuf, GstBuffer * outbuf)
369 guint8 *in_data, *out_data;
370 gpointer in_bufdata, out_bufdata;
371 gsize insize, outsize;
373 gint in_stride, out_stride;
375 in_bufdata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
376 out_bufdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE);
378 in_data = in_bufdata;
379 out_data = out_bufdata;
381 in_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 0);
382 out_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 0);
384 in_data += vcrop->crop_top * in_stride;
386 vcrop->crop_left * GST_VIDEO_INFO_COMP_PSTRIDE (&vcrop->in.info, 0);
388 dx = GST_VIDEO_INFO_WIDTH (&vcrop->out.info) *
389 GST_VIDEO_INFO_COMP_PSTRIDE (&vcrop->out.info, 0);
391 for (i = 0; i < GST_VIDEO_INFO_HEIGHT (&vcrop->out.info); ++i) {
392 memcpy (out_data, in_data, dx);
393 in_data += in_stride;
394 out_data += out_stride;
396 gst_buffer_unmap (inbuf, in_bufdata, insize);
397 gst_buffer_unmap (outbuf, out_bufdata, outsize);
401 gst_video_crop_transform_planar (GstVideoCrop * vcrop, GstBuffer * inbuf,
404 guint8 *y_out, *u_out, *v_out;
405 guint8 *y_in, *u_in, *v_in;
407 gpointer in_bufdata, out_bufdata;
408 gsize insize, outsize;
410 in_bufdata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
411 out_bufdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE);
418 (vcrop->crop_top * GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info,
419 0)) + vcrop->crop_left;
420 dx = GST_VIDEO_INFO_WIDTH (&vcrop->out.info) * 1;
422 for (i = 0; i < GST_VIDEO_INFO_HEIGHT (&vcrop->out.info); ++i) {
423 memcpy (y_out, y_in, dx);
424 y_in += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 0);
425 y_out += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 0);
430 (guint8 *) in_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->in.info, 1);
432 (guint8 *) out_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->out.info,
436 (vcrop->crop_top / 2) * GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 1);
437 u_in += vcrop->crop_left / 2;
440 (guint8 *) in_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->in.info, 2);
442 (guint8 *) out_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->out.info,
446 (vcrop->crop_top / 2) * GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 2);
447 v_in += vcrop->crop_left / 2;
449 dx = GST_ROUND_UP_2 (GST_VIDEO_INFO_WIDTH (&vcrop->out.info)) / 2;
451 for (i = 0; i < GST_ROUND_UP_2 (GST_VIDEO_INFO_HEIGHT (&vcrop->out.info)) / 2;
453 memcpy (u_out, u_in, dx);
454 memcpy (v_out, v_in, dx);
455 u_in += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 1);
456 u_out += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 1);
457 v_in += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 2);
458 v_out += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 2);
461 gst_buffer_unmap (inbuf, in_bufdata, insize);
462 gst_buffer_unmap (outbuf, out_bufdata, outsize);
466 gst_video_crop_transform (GstBaseTransform * trans, GstBuffer * inbuf,
469 GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
471 switch (vcrop->in.packing) {
472 case VIDEO_CROP_PIXEL_FORMAT_PACKED_SIMPLE:
473 gst_video_crop_transform_packed_simple (vcrop, inbuf, outbuf);
475 case VIDEO_CROP_PIXEL_FORMAT_PACKED_COMPLEX:
476 gst_video_crop_transform_packed_complex (vcrop, inbuf, outbuf);
478 case VIDEO_CROP_PIXEL_FORMAT_PLANAR:
479 gst_video_crop_transform_planar (vcrop, inbuf, outbuf);
482 g_assert_not_reached ();
489 gst_video_crop_transform_dimension (gint val, gint delta)
491 gint64 new_val = (gint64) val + (gint64) delta;
493 new_val = CLAMP (new_val, 1, G_MAXINT);
495 return (gint) new_val;
499 gst_video_crop_transform_dimension_value (const GValue * src_val,
500 gint delta, GValue * dest_val)
504 g_value_init (dest_val, G_VALUE_TYPE (src_val));
506 if (G_VALUE_HOLDS_INT (src_val)) {
507 gint ival = g_value_get_int (src_val);
509 ival = gst_video_crop_transform_dimension (ival, delta);
510 g_value_set_int (dest_val, ival);
511 } else if (GST_VALUE_HOLDS_INT_RANGE (src_val)) {
512 gint min = gst_value_get_int_range_min (src_val);
513 gint max = gst_value_get_int_range_max (src_val);
515 min = gst_video_crop_transform_dimension (min, delta);
516 max = gst_video_crop_transform_dimension (max, delta);
517 gst_value_set_int_range (dest_val, min, max);
518 } else if (GST_VALUE_HOLDS_LIST (src_val)) {
521 for (i = 0; i < gst_value_list_get_size (src_val); ++i) {
522 const GValue *list_val;
523 GValue newval = { 0, };
525 list_val = gst_value_list_get_value (src_val, i);
526 if (gst_video_crop_transform_dimension_value (list_val, delta, &newval))
527 gst_value_list_append_value (dest_val, &newval);
528 g_value_unset (&newval);
531 if (gst_value_list_get_size (dest_val) == 0) {
532 g_value_unset (dest_val);
536 g_value_unset (dest_val);
543 /* TODO use filter_caps */
545 gst_video_crop_transform_caps (GstBaseTransform * trans,
546 GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps)
552 vcrop = GST_VIDEO_CROP (trans);
554 GST_OBJECT_LOCK (vcrop);
556 GST_LOG_OBJECT (vcrop, "l=%d,r=%d,b=%d,t=%d",
557 vcrop->crop_left, vcrop->crop_right, vcrop->crop_bottom, vcrop->crop_top);
559 if (direction == GST_PAD_SRC) {
560 dx = vcrop->crop_left + vcrop->crop_right;
561 dy = vcrop->crop_top + vcrop->crop_bottom;
563 dx = 0 - (vcrop->crop_left + vcrop->crop_right);
564 dy = 0 - (vcrop->crop_top + vcrop->crop_bottom);
566 GST_OBJECT_UNLOCK (vcrop);
568 GST_LOG_OBJECT (vcrop, "transforming caps %" GST_PTR_FORMAT, caps);
570 other_caps = gst_caps_new_empty ();
572 for (i = 0; i < gst_caps_get_size (caps); ++i) {
574 GstStructure *structure, *new_structure;
575 GValue w_val = { 0, }, h_val = {
578 structure = gst_caps_get_structure (caps, i);
580 v = gst_structure_get_value (structure, "width");
581 if (!gst_video_crop_transform_dimension_value (v, dx, &w_val)) {
582 GST_WARNING_OBJECT (vcrop, "could not tranform width value with dx=%d"
583 ", caps structure=%" GST_PTR_FORMAT, dx, structure);
587 v = gst_structure_get_value (structure, "height");
588 if (!gst_video_crop_transform_dimension_value (v, dy, &h_val)) {
589 g_value_unset (&w_val);
590 GST_WARNING_OBJECT (vcrop, "could not tranform height value with dy=%d"
591 ", caps structure=%" GST_PTR_FORMAT, dy, structure);
595 new_structure = gst_structure_copy (structure);
596 gst_structure_set_value (new_structure, "width", &w_val);
597 gst_structure_set_value (new_structure, "height", &h_val);
598 g_value_unset (&w_val);
599 g_value_unset (&h_val);
600 GST_LOG_OBJECT (vcrop, "transformed structure %2d: %" GST_PTR_FORMAT
601 " => %" GST_PTR_FORMAT, i, structure, new_structure);
602 gst_caps_append_structure (other_caps, new_structure);
605 if (gst_caps_is_empty (other_caps)) {
606 gst_caps_unref (other_caps);
610 if (other_caps && filter_caps) {
611 GstCaps *tmp = gst_caps_intersect_full (filter_caps, other_caps,
612 GST_CAPS_INTERSECT_FIRST);
613 gst_caps_replace (&other_caps, tmp);
614 gst_caps_unref (tmp);
621 gst_video_crop_set_caps (GstBaseTransform * trans, GstCaps * incaps,
624 GstVideoCrop *crop = GST_VIDEO_CROP (trans);
626 if (!gst_video_crop_get_image_details_from_caps (crop, &crop->in, incaps))
629 if (!gst_video_crop_get_image_details_from_caps (crop, &crop->out, outcaps))
632 if (G_UNLIKELY ((crop->crop_left + crop->crop_right) >=
633 GST_VIDEO_INFO_WIDTH (&crop->in.info)
634 || (crop->crop_top + crop->crop_bottom) >=
635 GST_VIDEO_INFO_HEIGHT (&crop->in.info)))
636 goto cropping_too_much;
638 GST_LOG_OBJECT (crop, "incaps = %" GST_PTR_FORMAT ", outcaps = %"
639 GST_PTR_FORMAT, incaps, outcaps);
641 if ((crop->crop_left | crop->crop_right | crop->crop_top | crop->
643 GST_LOG_OBJECT (crop, "we are using passthrough");
644 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), TRUE);
646 GST_LOG_OBJECT (crop, "we are not using passthrough");
647 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), FALSE);
655 GST_DEBUG_OBJECT (crop, "failed to parse input caps %" GST_PTR_FORMAT,
661 GST_DEBUG_OBJECT (crop, "failed to parse output caps %" GST_PTR_FORMAT,
667 GST_DEBUG_OBJECT (crop, "we are cropping too much");
673 gst_video_crop_set_property (GObject * object, guint prop_id,
674 const GValue * value, GParamSpec * pspec)
676 GstVideoCrop *video_crop;
678 video_crop = GST_VIDEO_CROP (object);
680 /* don't modify while we are transforming */
681 GST_BASE_TRANSFORM_LOCK (GST_BASE_TRANSFORM_CAST (video_crop));
683 /* protect with the object lock so that we can read them */
684 GST_OBJECT_LOCK (video_crop);
687 video_crop->crop_left = g_value_get_int (value);
690 video_crop->crop_right = g_value_get_int (value);
693 video_crop->crop_top = g_value_get_int (value);
696 video_crop->crop_bottom = g_value_get_int (value);
699 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
702 GST_OBJECT_UNLOCK (video_crop);
704 GST_LOG_OBJECT (video_crop, "l=%d,r=%d,b=%d,t=%d",
705 video_crop->crop_left, video_crop->crop_right, video_crop->crop_bottom,
706 video_crop->crop_top);
708 gst_base_transform_reconfigure (GST_BASE_TRANSFORM (video_crop));
709 GST_BASE_TRANSFORM_UNLOCK (GST_BASE_TRANSFORM_CAST (video_crop));
713 gst_video_crop_get_property (GObject * object, guint prop_id, GValue * value,
716 GstVideoCrop *video_crop;
718 video_crop = GST_VIDEO_CROP (object);
720 GST_OBJECT_LOCK (video_crop);
723 g_value_set_int (value, video_crop->crop_left);
726 g_value_set_int (value, video_crop->crop_right);
729 g_value_set_int (value, video_crop->crop_top);
732 g_value_set_int (value, video_crop->crop_bottom);
735 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
738 GST_OBJECT_UNLOCK (video_crop);
742 plugin_init (GstPlugin * plugin)
744 GST_DEBUG_CATEGORY_INIT (videocrop_debug, "videocrop", 0, "videocrop");
746 if (gst_element_register (plugin, "videocrop", GST_RANK_NONE,
748 && gst_element_register (plugin, "aspectratiocrop", GST_RANK_NONE,
749 GST_TYPE_ASPECT_RATIO_CROP))
755 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
758 "Crops video into a user-defined region",
759 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)