[x264-devel] commit: Support custom cropping rectangles (Jason Garrett-Glaser )

git at videolan.org git at videolan.org
Fri Nov 19 23:50:13 CET 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Thu Nov 18 08:51:27 2010 -0800| [2eadb9436344cfccdcf9340545d813f4086c0ca4] | committer: Jason Garrett-Glaser 

Support custom cropping rectangles
Supposedly useful for 3D television applications.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=2eadb9436344cfccdcf9340545d813f4086c0ca4
---

 common/common.c   |    3 +++
 encoder/encoder.c |    9 +++++++++
 encoder/set.c     |    8 ++++----
 x264.c            |    3 +++
 x264.h            |   11 ++++++++++-
 5 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/common/common.c b/common/common.c
index 4e3f934..6c88556 100644
--- a/common/common.c
+++ b/common/common.c
@@ -952,6 +952,9 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->rc.f_complexity_blur = atof(value);
     OPT("zones")
         p->rc.psz_zones = strdup(value);
+    OPT("crop-rect")
+        b_error |= sscanf( value, "%u,%u,%u,%u", &p->crop_rect.i_left, &p->crop_rect.i_top,
+                                                 &p->crop_rect.i_right, &p->crop_rect.i_bottom ) != 4;
     OPT("psnr")
         p->analyse.b_psnr = atobool(value);
     OPT("ssim")
diff --git a/encoder/encoder.c b/encoder/encoder.c
index c42f48e..9fe58d0 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -417,6 +417,14 @@ static int x264_validate_parameters( x264_t *h )
         return -1;
     }
 
+    if( (h->param.crop_rect.i_left + h->param.crop_rect.i_right ) >= h->param.i_width ||
+        (h->param.crop_rect.i_top  + h->param.crop_rect.i_bottom) >= h->param.i_height )
+    {
+        x264_log( h, X264_LOG_ERROR, "invalid crop-rect %u,%u,%u,%u\n", h->param.crop_rect.i_left,
+                  h->param.crop_rect.i_top, h->param.crop_rect.i_right,  h->param.crop_rect.i_bottom );
+        return -1;
+    }
+
     if( h->param.i_threads == X264_THREADS_AUTO )
         h->param.i_threads = x264_cpu_num_processors() * (h->param.b_sliced_threads?2:3)/2;
     h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_THREAD_MAX );
@@ -1210,6 +1218,7 @@ int x264_encoder_reconfig( x264_t *h, x264_param_t *param )
     COPY( analyse.b_mixed_references );
     COPY( analyse.f_psy_rd );
     COPY( analyse.f_psy_trellis );
+    COPY( crop_rect );
     // can only twiddle these if they were enabled to begin with:
     if( h->param.analyse.i_me_method >= X264_ME_ESA || param->analyse.i_me_method < X264_ME_ESA )
         COPY( analyse.i_me_method );
diff --git a/encoder/set.c b/encoder/set.c
index ce1e9e8..6cf0c6a 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -192,10 +192,10 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     sps->b_mb_adaptive_frame_field = param->b_interlaced;
     sps->b_direct8x8_inference = 1;
 
-    sps->crop.i_left   = 0;
-    sps->crop.i_top    = 0;
-    sps->crop.i_right  = sps->i_mb_width*16 - param->i_width;
-    sps->crop.i_bottom = (sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only;
+    sps->crop.i_left   = param->crop_rect.i_left;
+    sps->crop.i_top    = param->crop_rect.i_top;
+    sps->crop.i_right  = param->crop_rect.i_right + sps->i_mb_width*16 - param->i_width;
+    sps->crop.i_bottom = (param->crop_rect.i_bottom + sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only;
     sps->b_crop = sps->crop.i_left  || sps->crop.i_top ||
                   sps->crop.i_right || sps->crop.i_bottom;
 
diff --git a/x264.c b/x264.c
index 387d7e1..bba17b8 100644
--- a/x264.c
+++ b/x264.c
@@ -680,6 +680,8 @@ static void help( x264_param_t *defaults, int longhelp )
     H2( "      --nal-hrd <string>      Signal HRD information (requires vbv-bufsize)\n"
         "                                  - none, vbr, cbr (cbr not allowed in .mp4)\n" );
     H2( "      --pic-struct            Force pic_struct in Picture Timing SEI\n" );
+    H2( "      --crop-rect <string>    Add 'left,top,right,bottom' to the bitstream-level\n"
+        "                              cropping rectangle\n" );
 
     H0( "\n" );
     H0( "Input/Output:\n" );
@@ -913,6 +915,7 @@ static struct option long_options[] =
     { "tcfile-out",  required_argument, NULL, OPT_TCFILE_OUT },
     { "timebase",    required_argument, NULL, OPT_TIMEBASE },
     { "pic-struct",        no_argument, NULL, 0 },
+    { "crop-rect",   required_argument, NULL, 0 },
     { "nal-hrd",     required_argument, NULL, 0 },
     { "pulldown",    required_argument, NULL, OPT_PULLDOWN },
     { "fake-interlaced",   no_argument, NULL, 0 },
diff --git a/x264.h b/x264.h
index aa0df35..ce79d40 100644
--- a/x264.h
+++ b/x264.h
@@ -39,7 +39,7 @@
 
 #include <stdarg.h>
 
-#define X264_BUILD 107
+#define X264_BUILD 108
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -379,6 +379,15 @@ typedef struct x264_param_t
         char        *psz_zones;     /* alternate method of specifying zones */
     } rc;
 
+    /* Cropping Rectangle parameters: added to those implicitly defined by
+       non-mod16 video resolutions. */
+    struct {
+        unsigned int i_left;
+        unsigned int i_top;
+        unsigned int i_right;
+        unsigned int i_bottom;
+    } crop_rect;
+
     /* Muxing parameters */
     int b_aud;                  /* generate access unit delimiters */
     int b_repeat_headers;       /* put SPS/PPS before each keyframe */



More information about the x264-devel mailing list