From c22e82ad0081856466a92a6e47a72b3ea9b5628c Mon Sep 17 00:00:00 2001 From: jstebbins Date: Sun, 25 Apr 2010 21:15:43 +0000 Subject: bump ffmpeg to rev 22950 offset ffmpeg seeks by value of initial timestamp since it can be non-zero catch pix fmt that is unsupported by swscale, log it, skip the track use new ffmpeg avg_frame_rate for more accurate framerate estimate git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3267 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/decavcodec.c | 10 ++++++++-- libhb/stream.c | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'libhb') diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index a506154db..0a9f63fec 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -1027,8 +1027,14 @@ static void init_ffmpeg_context( hb_work_object_t *w ) // Because the time bases are so screwed up, we only take values // in the range 8fps - 64fps. AVRational tb; - if ( st->time_base.num * 64 > st->time_base.den && - st->time_base.den > st->time_base.num * 8 ) + if ( st->avg_frame_rate.den * 64 > st->avg_frame_rate.num && + st->avg_frame_rate.num > st->avg_frame_rate.den * 8 ) + { + tb.num = st->avg_frame_rate.den; + tb.den = st->avg_frame_rate.num; + } + else if ( st->time_base.num * 64 > st->time_base.den && + st->time_base.den > st->time_base.num * 8 ) { tb = st->time_base; } diff --git a/libhb/stream.c b/libhb/stream.c index d2d2a4a47..caed365cd 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -1259,6 +1259,14 @@ int hb_stream_read( hb_stream_t * src_stream, hb_buffer_t * b ) return hb_ts_stream_decode( src_stream, b ); } +int64_t ffmpeg_initial_timestamp( hb_stream_t * stream ) +{ + AVStream *s = stream->ffmpeg_ic->streams[stream->ffmpeg_video_id]; + if ( s->nb_index_entries < 1 ) + return 0; + + return s->index_entries[0].timestamp; +} int hb_stream_seek_chapter( hb_stream_t * stream, int chapter_num ) { @@ -1284,7 +1292,7 @@ int hb_stream_seek_chapter( hb_stream_t * stream, int chapter_num ) stream->chapter = chapter_num - 1; stream->chapter_end = sum_dur; - int64_t pos = ( ( ( sum_dur - chapter->duration ) * AV_TIME_BASE ) / 90000 ); + int64_t pos = ( ( ( sum_dur - chapter->duration ) * AV_TIME_BASE ) / 90000 ) + ffmpeg_initial_timestamp( stream ); hb_deep_log( 2, "Seeking to chapter %d: starts %"PRId64", ends %"PRId64", AV pos %"PRId64, chapter_num, sum_dur - chapter->duration, sum_dur, pos); @@ -1302,7 +1310,7 @@ int hb_stream_seek_chapter( hb_stream_t * stream, int chapter_num ) // that causes the problem. since hb_stream_seek_chapter // is called before we start reading, make sure // we do a seek here. - av_seek_frame( stream->ffmpeg_ic, -1, 0LL, AVSEEK_FLAG_BACKWARD ); + av_seek_frame( stream->ffmpeg_ic, -1, ffmpeg_initial_timestamp( stream ), AVSEEK_FLAG_BACKWARD ); } return 1; } @@ -2857,6 +2865,13 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream ) avcodec_find_decoder( ic->streams[i]->codec->codec_id ) && title->video_codec == 0 ) { + AVCodecContext *context = ic->streams[i]->codec; + if ( context->pix_fmt != PIX_FMT_YUV420P && + !sws_isSupportedInput( context->pix_fmt ) ) + { + hb_log( "ffmpeg_title_scan: Unsupported color space" ); + continue; + } title->video_id = i; stream->ffmpeg_video_id = i; @@ -3116,7 +3131,7 @@ static int ffmpeg_seek_ts( hb_stream_t *stream, int64_t ts ) AVFormatContext *ic = stream->ffmpeg_ic; int64_t pos; - pos = ts * AV_TIME_BASE / 90000; + pos = ts * AV_TIME_BASE / 90000 + ffmpeg_initial_timestamp( stream ); stream->need_keyframe = 1; // Seek to the nearest timestamp before that requested where // there is an I-frame -- cgit v1.2.3