From 2c2aae581e34e3ba891fc0374be17d29718b41ff Mon Sep 17 00:00:00 2001 From: jstebbins Date: Sun, 2 Feb 2014 16:29:44 +0000 Subject: libhb: fix problem with avcodec audio sample_rate libavcodec does not yet consistently set AVFrame.sample_rate. So when it is not set, use AVCodecContext.sample_rate and log a warning. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6011 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/decavcodec.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'libhb/decavcodec.c') diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index b4daf3cdc..7409bc8db 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -698,7 +698,16 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf, if (len > 0 && got_frame) { info->rate_base = 1; - info->rate = frame->sample_rate; + // libavcoded doesn't consistently set frame->sample_rate + if (frame->sample_rate != 0) + { + info->rate = frame->sample_rate; + } + else + { + info->rate = context->sample_rate; + hb_log("decavcodecaBSInfo: warning: invalid frame sample_rate! Using context sample_rate."); + } info->samples_per_frame = frame->nb_samples; int bps = av_get_bits_per_sample(context->codec_id); @@ -2144,8 +2153,18 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data, if (got_frame) { hb_buffer_t *out; + int samplerate; + // libavcoded doesn't yet consistently set frame->sample_rate + if (pv->frame->sample_rate != 0) + { + samplerate = pv->frame->sample_rate; + } + else + { + samplerate = context->sample_rate; + } double duration = (90000. * pv->frame->nb_samples / - (double)pv->frame->sample_rate); + (double)samplerate); if (audio->config.out.codec & HB_ACODEC_PASS_FLAG) { -- cgit v1.2.3