Skip to content

Commit

Permalink
Merge from avformat branch
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk/libhb@60 b64f7644-9d1e-0410-96f1-a4d463321fa5
  • Loading branch information
titer committed Apr 17, 2006
1 parent f1a3a62 commit 2592141
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 146 deletions.
1 change: 1 addition & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ int hb_calc_bitrate( hb_job_t * job, int size )
switch( job->mux )
{
case HB_MUX_MP4:
case HB_MUX_PSP:
overhead = 6;
break;
case HB_MUX_AVI:
Expand Down
5 changes: 3 additions & 2 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ struct hb_job_s
file: file path */
#define HB_MUX_MASK 0xFF0000
#define HB_MUX_MP4 0x010000
#define HB_MUX_AVI 0x020000
#define HB_MUX_OGM 0x040000
#define HB_MUX_PSP 0x020000
#define HB_MUX_AVI 0x040000
#define HB_MUX_OGM 0x080000
int mux;
char * file;

Expand Down
14 changes: 12 additions & 2 deletions encavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
context->gop_size = 10 * job->vrate / job->vrate_base;
context->pix_fmt = PIX_FMT_YUV420P;

if( job->mux & HB_MUX_MP4 )
if( job->mux & ( HB_MUX_MP4 | HB_MUX_PSP ) )
{
context->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
if( job->mux & HB_MUX_PSP )
{
context->flags |= CODEC_FLAG_BITEXACT;
}
if( job->grayscale )
{
context->flags |= CODEC_FLAG_GRAY;
Expand Down Expand Up @@ -110,11 +114,17 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
}
pv->context = context;

if( ( job->mux & HB_MUX_MP4 ) && job->pass != 1 )
if( ( job->mux & ( HB_MUX_MP4 | HB_MUX_PSP ) ) && job->pass != 1 )
{
#if 0
/* Hem hem */
w->config->mpeg4.length = 15;
memcpy( w->config->mpeg4.bytes, context->extradata + 15, 15 );
#else
w->config->mpeg4.length = context->extradata_size;
memcpy( w->config->mpeg4.bytes, context->extradata,
context->extradata_size );
#endif
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions encfaac.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ hb_work_object_t hb_encfaac =
int encfaacInit( hb_work_object_t * w, hb_job_t * job )
{
hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
w->private_data = pv;

faacEncConfigurationPtr cfg;
uint8_t * bytes;
unsigned long length;

w->private_data = pv;

pv->job = job;

Expand All @@ -67,8 +69,6 @@ int encfaacInit( hb_work_object_t * w, hb_job_t * job )
hb_log( "faacEncSetConfiguration failed" );
}

uint8_t * bytes;
unsigned long length;
if( faacEncGetDecoderSpecificInfo( pv->faac, &bytes, &length ) < 0 )
{
hb_log( "faacEncGetDecoderSpecificInfo failed" );
Expand Down
60 changes: 15 additions & 45 deletions encx264.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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;
Expand All @@ -63,6 +64,7 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
param.i_log_level = X264_LOG_NONE;
if( job->h264_13 )
{
param.i_threads = 1;
param.b_cabac = 0;
param.i_level_idc = 13;
}
Expand Down Expand Up @@ -98,17 +100,17 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
hb_log( "encx264: opening libx264 (pass %d)", job->pass );
pv->x264 = x264_encoder_open( &param );

x264_encoder_headers( pv->x264, &nal, &nal_count );
w->config->mpeg4.length = 0;

/* Sequence Parameter Set */
w->config->h264.sps_length = 1 + nal[1].i_payload;
w->config->h264.sps[0] = 0x67;
memcpy( &w->config->h264.sps[1], nal[1].p_payload, nal[1].i_payload );
x264_encoder_headers( pv->x264, &nal, &nal_count );

/* Picture Parameter Set */
w->config->h264.pps_length = 1 + nal[2].i_payload;
w->config->h264.pps[0] = 0x68;
memcpy( &w->config->h264.pps[1], nal[2].p_payload, nal[2].i_payload );
for( i = 0; i < nal_count; i++ )
{
size = sizeof( w->config->mpeg4.bytes ) - w->config->mpeg4.length;
x264_nal_encode( &w->config->mpeg4.bytes[w->config->mpeg4.length],
&size, 1, &nal[i] );
w->config->mpeg4.length += size;
}

x264_picture_alloc( &pv->pic_in, X264_CSP_I420,
job->width, job->height );
Expand Down Expand Up @@ -158,51 +160,19 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,

/* Should be way too large */
buf = hb_buffer_init( 3 * job->width * job->height / 2 );
buf->size = 0;
buf->start = in->start;
buf->stop = in->stop;
buf->key = 0;
buf->key = ( pv->pic_out.i_type == X264_TYPE_IDR );

buf->size = 0;
for( i = 0; i < i_nal; i++ )
{
int size, data;

data = buf->alloc - buf->size;
if( ( size = x264_nal_encode( buf->data + buf->size, &data,
1, &nal[i] ) ) < 1 )
if( ( size = x264_nal_encode( &buf->data[buf->size], &data,
1, &nal[i] ) ) > 0 )
{
continue;
}

if( job->mux & HB_MUX_AVI )
{
if( nal[i].i_ref_idc == NAL_PRIORITY_HIGHEST )
{
buf->key = 1;
}
buf->size += size;
continue;
}

/* H.264 in .mp4 */
switch( buf->data[buf->size+4] & 0x1f )
{
case 0x7:
case 0x8:
/* SPS, PPS */
break;

default:
/* H.264 in mp4 (stolen from mp4creator) */
buf->data[buf->size+0] = ( ( size - 4 ) >> 24 ) & 0xFF;
buf->data[buf->size+1] = ( ( size - 4 ) >> 16 ) & 0xFF;
buf->data[buf->size+2] = ( ( size - 4 ) >> 8 ) & 0xFF;
buf->data[buf->size+3] = ( ( size - 4 ) >> 0 ) & 0xFF;
if( nal[i].i_ref_idc == NAL_PRIORITY_HIGHEST )
{
buf->key = 1;
}
buf->size += size;
}
}

Expand Down
23 changes: 21 additions & 2 deletions hb.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void hb_set_size( hb_job_t * job, int aspect, int pixels )
int croppedAspect = title->aspect * title->height * croppedWidth /
croppedHeight / title->width;
int addCrop;
int i, w, h;

if( aspect <= 0 )
{
Expand Down Expand Up @@ -296,11 +297,29 @@ void hb_set_size( hb_job_t * job, int aspect, int pixels )
else if( aspect > croppedAspect )
{
/* Need to crop on the top and bottom */
/* TODO */
addCrop = croppedHeight - croppedWidth * title->aspect *
title->height / aspect / title->width;
if( addCrop & 3 )
{
addCrop = ( addCrop + 1 ) / 2;
job->crop[0] += addCrop;
job->crop[1] += addCrop;
}
else if( addCrop & 2 )
{
addCrop /= 2;
job->crop[0] += addCrop - 1;
job->crop[1] += addCrop + 1;
}
else
{
addCrop /= 2;
job->crop[0] += addCrop;
job->crop[1] += addCrop;
}
}

/* Compute a resolution from the number of pixels and aspect */
int i, w, h;
for( i = 0;; i++ )
{
w = 16 * i;
Expand Down
8 changes: 0 additions & 8 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ union hb_esconfig_u
int length;
} mpeg4;

struct
{
uint8_t sps[HB_CONFIG_MAX_SIZE];
int sps_length;
uint8_t pps[HB_CONFIG_MAX_SIZE];
int pps_length;
} h264;

struct
{
uint8_t bytes[HB_CONFIG_MAX_SIZE];
Expand Down
1 change: 1 addition & 0 deletions muxcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static void MuxerFunc( void * _mux )
switch( job->mux )
{
case HB_MUX_MP4:
case HB_MUX_PSP:
m = hb_mux_mp4_init( job );
break;
case HB_MUX_AVI:
Expand Down
Loading

0 comments on commit 2592141

Please sign in to comment.