X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fencavcodec.c;h=22eb286d524158c8e300c04d8f5143f623e7bfaa;hb=4f0019f03c2e85e8634150ff0c9a31bee6d35ce5;hp=f3837b3e74e86ab8bd93ec8dbf48ef617ba8e4e6;hpb=1d9c122201261c9f3098a417ed140106e0d6ba0d;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index f3837b3e..22eb286d 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -5,8 +5,7 @@ It may be used under the terms of the GNU General Public License. */ #include "hb.h" - -#include "libavcodec/avcodec.h" +#include "hbffmpeg.h" struct hb_work_private_s { @@ -32,6 +31,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) { AVCodec * codec; AVCodecContext * context; + int rate_num, rate_den; hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) ); w->private_data = pv; @@ -71,23 +71,48 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) { context->global_quality = FF_QP2LAMBDA * job->vquality + 0.5; } - context->mb_decision = 1; + context->mb_decision = 1; hb_log( "encavcodec: encoding at constant quantizer %d", context->global_quality ); } context->width = job->width; context->height = job->height; - context->time_base = (AVRational) { job->vrate_base, job->vrate }; + rate_num = job->vrate_base; + rate_den = job->vrate; + if (rate_den == 27000000) + { + int ii; + for (ii = 0; ii < hb_video_rates_count; ii++) + { + if (abs(rate_num - hb_video_rates[ii].rate) < 10) + { + rate_num = hb_video_rates[ii].rate; + break; + } + } + } + hb_reduce(&rate_num, &rate_den, rate_num, rate_den); + if ((rate_num & ~0xFFFF) || (rate_den & ~0xFFFF)) + { + hb_log( "encavcodec: truncating framerate %d / %d", + rate_num, rate_den ); + } + while ((rate_num & ~0xFFFF) || (rate_den & ~0xFFFF)) + { + rate_num >>= 1; + rate_den >>= 1; + } + context->time_base = (AVRational) { rate_num, rate_den }; context->gop_size = 10 * job->vrate / job->vrate_base; context->pix_fmt = PIX_FMT_YUV420P; - if( job->pixel_ratio ) + if( job->anamorphic.mode ) { - context->sample_aspect_ratio.num = job->pixel_aspect_width; - context->sample_aspect_ratio.den = job->pixel_aspect_height; + context->sample_aspect_ratio.num = job->anamorphic.par_width; + context->sample_aspect_ratio.den = job->anamorphic.par_height; hb_log( "encavcodec: encoding with stored aspect %d/%d", - job->pixel_aspect_width, job->pixel_aspect_height ); + job->anamorphic.par_width, job->anamorphic.par_height ); } if( job->mux & ( HB_MUX_MP4 | HB_MUX_PSP ) ) @@ -133,7 +158,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) } } - if( avcodec_open( context, codec ) ) + if( hb_avcodec_open( context, codec ) ) { hb_log( "hb_work_encavcodec_init: avcodec_open failed" ); } @@ -166,9 +191,9 @@ void encavcodecClose( hb_work_object_t * w ) if( pv->context ) { - hb_log( "encavcodec: closing libavcodec" ); + hb_deep_log( 2, "encavcodec: closing libavcodec" ); avcodec_flush_buffers( pv->context ); - avcodec_close( pv->context ); + hb_avcodec_close( pv->context ); } if( pv->file ) { @@ -211,7 +236,7 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, frame->quality = pv->context->global_quality; /* 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 = avcodec_encode_video( pv->context, buf->data, buf->alloc, frame ); buf->start = in->start;