summaryrefslogtreecommitdiffstats
path: root/libhb/decavcodec.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2011-10-17 16:24:24 +0000
committerjstebbins <[email protected]>2011-10-17 16:24:24 +0000
commit1c0ae631e0898549b16b029e55e4526040872d5d (patch)
tree78ed68c3259db2f6af5b78ba43d26a3e2b477051 /libhb/decavcodec.c
parent49fad04f4365f0c3c01583dabd8d261ec76505f3 (diff)
fix a problem with resolution changes in h.264
First, the scaling code in decavcodec.c was broken and didn't properly compensate for frames that had a different resolution than the rest of the stream. Second, libav can not handle resolution changes when doing frame based multi-threading. So disable threading when resolution changes are detected. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4295 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/decavcodec.c')
-rw-r--r--libhb/decavcodec.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index 28498273c..6cb44b160 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -74,6 +74,7 @@ struct hb_work_private_s
hb_title_t *title;
AVCodecContext *context;
AVCodecParserContext *parser;
+ int threads;
int video_codec_opened;
hb_list_t *list;
double duration; // frame duration (for video)
@@ -91,6 +92,9 @@ struct hb_work_private_s
pts_heap_t pts_heap;
void* buffer;
struct SwsContext *sws_context; // if we have to rescale or convert color space
+ int sws_width;
+ int sws_height;
+ int sws_pix_fmt;
hb_downmix_t *downmix;
int cadence[12];
int wait_for_keyframe;
@@ -548,14 +552,23 @@ static hb_buffer_t *copy_frame( hb_work_private_t *pv, AVFrame *frame )
AVPicture dstpic;
avpicture_fill( &dstpic, dst, PIX_FMT_YUV420P, w, h );
- if ( ! pv->sws_context )
+ if ( ! pv->sws_context ||
+ pv->sws_width != context->width ||
+ pv->sws_height != context->height ||
+ pv->sws_pix_fmt != context->pix_fmt )
{
- pv->sws_context = hb_sws_get_context( w, h, context->pix_fmt,
- w, h, PIX_FMT_YUV420P,
- SWS_LANCZOS|SWS_ACCURATE_RND);
+ if( pv->sws_context )
+ sws_freeContext( pv->sws_context );
+ pv->sws_context = hb_sws_get_context(
+ context->width, context->height, context->pix_fmt,
+ w, h, PIX_FMT_YUV420P,
+ SWS_LANCZOS|SWS_ACCURATE_RND);
+ pv->sws_width = context->width;
+ pv->sws_height = context->height;
+ pv->sws_pix_fmt = context->pix_fmt;
}
sws_scale( pv->sws_context, (const uint8_t* const *)frame->data,
- frame->linesize, 0, h,
+ frame->linesize, 0, context->height,
dstpic.data, dstpic.linesize );
}
else
@@ -979,6 +992,11 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
pv->title = w->title;
pv->list = hb_list_init();
+ if( pv->job )
+ {
+ if( !pv->job->title || !pv->job->title->has_resolution_change )
+ pv->threads = HB_FFMPEG_THREADS_AUTO;
+ }
if ( pv->title->opaque_priv )
{
AVFormatContext *ic = (AVFormatContext*)pv->title->opaque_priv;
@@ -994,7 +1012,7 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
pv->context->error_recognition = 1;
pv->context->error_concealment = FF_EC_GUESS_MVS|FF_EC_DEBLOCK;
- if ( hb_avcodec_open( pv->context, codec, NULL, pv->job ? HB_FFMPEG_THREADS_AUTO : 0 ) )
+ if ( hb_avcodec_open( pv->context, codec, NULL, pv->threads ) )
{
hb_log( "decavcodecvInit: avcodec_open failed" );
return 1;
@@ -1156,7 +1174,7 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
return HB_WORK_OK;
}
// disable threaded decoding for scan, can cause crashes
- if ( hb_avcodec_open( pv->context, codec, NULL, pv->job ? HB_FFMPEG_THREADS_AUTO : 0 ) )
+ if ( hb_avcodec_open( pv->context, codec, NULL, pv->threads ) )
{
hb_log( "decavcodecvWork: avcodec_open failed" );
*buf_out = hb_buffer_init( 0 );;