summaryrefslogtreecommitdiffstats
path: root/libhb/encx264.c
diff options
context:
space:
mode:
authorrhester <[email protected]>2006-09-30 16:21:26 +0000
committerrhester <[email protected]>2006-09-30 16:21:26 +0000
commit1806e33ca8df880e33657d3a30e537ae620fadef (patch)
tree69482a657f855d09d669e94ec0bd3251d6092406 /libhb/encx264.c
parent5f8684be8ecc912a8828ae3c21857125255a590b (diff)
HandBrake 0.7.1a1
Made H.264 baseline levels more generic Added iPod 640x480 support to libhb, HBTest and MacOS X GUI Added proper iPod 640x480 muxing Modified rate control for more accurate ending video bitrates Updated ffmpeg and x264 base sources to more current levels Removed inlined ff_get_fourcc (now in ffmpeg) Updated patches for xvidcore, libdvdread, x264, and ffmpeg Relocated contrib files to local web server and updated version files to new site Renamed contrib files and patches to consistent naming standard Updated contrib Jamfile to support new patches and naming standard git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@70 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/encx264.c')
-rw-r--r--libhb/encx264.c89
1 files changed, 53 insertions, 36 deletions
diff --git a/libhb/encx264.c b/libhb/encx264.c
index 13faadc39..53950fa5e 100644
--- a/libhb/encx264.c
+++ b/libhb/encx264.c
@@ -1,8 +1,8 @@
/* $Id: encx264.c,v 1.21 2005/11/04 13:09:41 titer Exp $
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.m0k.org/>.
- It may be used under the terms of the GNU General Public License. */
+This file is part of the HandBrake source code.
+Homepage: <http://handbrake.m0k.org/>.
+It may be used under the terms of the GNU General Public License. */
#include <stdarg.h>
@@ -29,32 +29,32 @@ struct hb_work_private_s
x264_t * x264;
x264_picture_t pic_in;
x264_picture_t pic_out;
-
+
char filename[1024];
};
/***********************************************************************
- * hb_work_encx264_init
- ***********************************************************************
- *
- **********************************************************************/
+* hb_work_encx264_init
+***********************************************************************
+*
+**********************************************************************/
int encx264Init( hb_work_object_t * w, hb_job_t * job )
{
x264_param_t param;
x264_nal_t * nal;
int nal_count;
int i, size;
-
+
hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
w->private_data = pv;
-
+
pv->job = job;
-
+
memset( pv->filename, 0, 1024 );
hb_get_tempory_filename( job->h, pv->filename, "x264.log" );
-
+
x264_param_default( &param );
-
+
param.i_threads = hb_get_cpu_count();
param.i_width = job->width;
param.i_height = job->height;
@@ -62,16 +62,19 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
param.i_fps_den = job->vrate_base;
param.i_keyint_max = 20 * job->vrate / job->vrate_base;
param.i_log_level = X264_LOG_NONE;
- if( job->h264_13 )
+
+ if( job->h264_level )
{
- param.i_threads = 1;
- param.b_cabac = 0;
- param.i_level_idc = 13;
+ param.i_threads = 1;
+ param.b_cabac = 0;
+ param.i_level_idc = job->h264_level;
+ hb_log( "encx264: encoding at level %i",
+ param.i_level_idc );
}
-
+
/* Slightly faster with minimal quality lost */
param.analyse.i_subpel_refine = 4;
-
+
if( job->vquality >= 0.0 && job->vquality <= 1.0 )
{
/* Constant QP */
@@ -81,29 +84,40 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
}
else
{
- /* Rate control */
- param.rc.b_cbr = 1;
+
+ /* Rate control */
+ /* no longer in x264 - see rc.i_rc_method in x264.h */
+ /* param.rc.b_cbr = 1; */
+
+ /* these were the only settings I could use to get accurate ending video bitrate */
+ param.rc.i_rc_method = X264_RC_CRF;
+ param.rc.i_vbv_max_bitrate = job->vbitrate;
+ param.rc.i_vbv_buffer_size = 224;
+ param.rc.i_rf_constant = 1;
+
param.rc.i_bitrate = job->vbitrate;
switch( job->pass )
{
case 1:
+ param.rc.i_rc_method = X264_RC_ABR;
param.rc.b_stat_write = 1;
param.rc.psz_stat_out = pv->filename;
break;
case 2:
+ param.rc.i_rc_method = X264_RC_ABR;
param.rc.b_stat_read = 1;
param.rc.psz_stat_in = pv->filename;
break;
}
}
-
+
hb_log( "encx264: opening libx264 (pass %d)", job->pass );
pv->x264 = x264_encoder_open( &param );
-
+
w->config->mpeg4.length = 0;
-
+
x264_encoder_headers( pv->x264, &nal, &nal_count );
-
+
for( i = 0; i < nal_count; i++ )
{
size = sizeof( w->config->mpeg4.bytes ) - w->config->mpeg4.length;
@@ -111,10 +125,10 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
&size, 1, &nal[i] );
w->config->mpeg4.length += size;
}
-
+
x264_picture_alloc( &pv->pic_in, X264_CSP_I420,
job->width, job->height );
-
+
return 0;
}
@@ -122,12 +136,12 @@ void encx264Close( hb_work_object_t * w )
{
hb_work_private_t * pv = w->private_data;
x264_encoder_close( pv->x264 );
-
+
/* TODO */
}
int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
- hb_buffer_t ** buf_out )
+ hb_buffer_t ** buf_out )
{
hb_work_private_t * pv = w->private_data;
hb_job_t * job = pv->job;
@@ -135,7 +149,7 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
int i_nal;
x264_nal_t * nal;
int i;
-
+
/* XXX avoid this memcpy ? */
memcpy( pv->pic_in.img.plane[0], in->data, job->width * job->height );
if( job->grayscale )
@@ -151,19 +165,22 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
memcpy( pv->pic_in.img.plane[2], in->data + 5 * job->width *
job->height / 4, job->width * job->height / 4 );
}
-
+
pv->pic_in.i_type = X264_TYPE_AUTO;
pv->pic_in.i_qpplus1 = 0;
-
+
x264_encoder_encode( pv->x264, &nal, &i_nal,
&pv->pic_in, &pv->pic_out );
-
+
+
+
/* Should be way too large */
buf = hb_buffer_init( 3 * job->width * job->height / 2 );
buf->start = in->start;
buf->stop = in->stop;
buf->key = ( pv->pic_out.i_type == X264_TYPE_IDR );
-
+
+
buf->size = 0;
for( i = 0; i < i_nal; i++ )
{
@@ -175,9 +192,9 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
buf->size += size;
}
}
-
+
*buf_out = buf;
-
+
return HB_WORK_OK;
}