Commit fa28f5b9 authored by Fiona Glaser's avatar Fiona Glaser

Support custom cropping rectangles

Supposedly useful for 3D television applications.
parent 1382552b
......@@ -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")
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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 },
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment