X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fencx264.c;h=97de03e8ed3889b6411b1fe98822a3ac26412200;hb=8425b4e14041ee668806cff29e458ae73bcd894f;hp=ebd9f4bb523122927be66fe85de46ffee30e6d4d;hpb=7ab647afcdeaf203560ec098cce1f03c451e4e99;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/encx264.c b/libhb/encx264.c index ebd9f4bb..97de03e8 100644 --- a/libhb/encx264.c +++ b/libhb/encx264.c @@ -108,9 +108,6 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) param.i_level_idc ); } - /* Slightly faster with minimal quality lost */ - param.analyse.i_subpel_refine = 4; - /* This section passes the string x264opts to libx264 for parsing into parameter names and values. @@ -198,8 +195,21 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) /* set up the VUI color model & gamma to match what the COLR atom * set in muxmp4.c says. See libhb/muxmp4.c for notes. */ - - if ( job->title->height >= 720 ) + if( job->color_matrix == 1 ) + { + // ITU BT.601 DVD or SD TV content + param.vui.i_colorprim = 6; + param.vui.i_transfer = 1; + param.vui.i_colmatrix = 6; + } + else if( job->color_matrix == 2 ) + { + // ITU BT.709 HD content + param.vui.i_colorprim = 1; + param.vui.i_transfer = 1; + param.vui.i_colmatrix = 1; + } + else if ( job->title->width >= 1280 || job->title->height >= 720 ) { // we guess that 720p or above is ITU BT.709 HD content param.vui.i_colorprim = 1; @@ -286,7 +296,7 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) } } - hb_log( "encx264: opening libx264 (pass %d)", job->pass ); + hb_deep_log( 2, "encx264: opening libx264 (pass %d)", job->pass ); pv->x264 = x264_encoder_open( ¶m ); x264_encoder_headers( pv->x264, &nal, &nal_count ); @@ -302,6 +312,7 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) x264_picture_alloc( &pv->pic_in, X264_CSP_I420, job->width, job->height ); + pv->pic_in.img.i_stride[2] = pv->pic_in.img.i_stride[1] = ( ( job->width + 1 ) >> 1 ); pv->x264_allocated_pic = pv->pic_in.img.plane[0]; if (job->areBframes) @@ -381,7 +392,7 @@ static hb_buffer_t *nal_encode( hb_work_object_t *w, x264_picture_t *pic_out, hb_job_t *job = pv->job; /* Should be way too large */ - buf = hb_buffer_init( 3 * job->width * job->height / 2 ); + buf = hb_video_buffer_init( job->width, job->height ); buf->size = 0; buf->frametype = 0; @@ -495,17 +506,18 @@ static hb_buffer_t *x264_encode( hb_work_object_t *w, hb_buffer_t *in ) /* Point x264 at our current buffers Y(UV) data. */ pv->pic_in.img.plane[0] = in->data; + int uvsize = ( (job->width + 1) >> 1 ) * ( (job->height + 1) >> 1 ); if( job->grayscale ) { /* XXX x264 has currently no option for grayscale encoding */ - memset( pv->pic_in.img.plane[1], 0x80, job->width * job->height / 4 ); - memset( pv->pic_in.img.plane[2], 0x80, job->width * job->height / 4 ); + memset( pv->pic_in.img.plane[1], 0x80, uvsize ); + memset( pv->pic_in.img.plane[2], 0x80, uvsize ); } else { /* Point x264 at our buffers (Y)UV data */ pv->pic_in.img.plane[1] = in->data + job->width * job->height; - pv->pic_in.img.plane[2] = in->data + 5 * job->width * job->height / 4; + pv->pic_in.img.plane[2] = pv->pic_in.img.plane[1] + uvsize; } if( in->new_chap && job->chapter_markers ) { @@ -566,6 +578,8 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_work_private_t *pv = w->private_data; hb_buffer_t *in = *buf_in; + *buf_out = NULL; + if( in->size <= 0 ) { // EOF on input. Flush any frames still in the decoder then @@ -582,11 +596,14 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in, break; hb_buffer_t *buf = nal_encode( w, &pic_out, i_nal, nal ); - if ( last_buf == NULL ) - *buf_out = buf; - else - last_buf->next = buf; - last_buf = buf; + if ( buf ) + { + if ( last_buf == NULL ) + *buf_out = buf; + else + last_buf->next = buf; + last_buf = buf; + } } // Flushed everything - add the eof to the end of the chain. if ( last_buf == NULL ) @@ -638,11 +655,14 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in, new_stop = orig_stop; in->stop = new_stop; hb_buffer_t *buf = x264_encode( w, in ); - if ( last_buf == NULL ) - *buf_out = buf; - else - last_buf->next = buf; - last_buf = buf; + if ( buf ) + { + if ( last_buf == NULL ) + *buf_out = buf; + else + last_buf->next = buf; + last_buf = buf; + } in->start = new_stop; } }