From: John Stebbins Date: Thu, 11 May 2017 20:17:51 +0000 (-0700) Subject: encavcodecaudio: work around lame bug X-Git-Tag: 1.1.0~571 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f17f5c08129a39da12352828d6ec145dc448261;p=handbrake encavcodecaudio: work around lame bug On windows builds, there is an upstream bug in the lame encoder that causes an extra output packet that has the same timestamp as the second to last packet. This causes an error during muxing. Drop the packet with the duplicate timestamp. Fixes https://github.com/HandBrake/HandBrake/issues/726 --- diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c index b7f2969d9..5f95c7383 100644 --- a/libhb/encavcodecaudio.c +++ b/libhb/encavcodecaudio.c @@ -24,6 +24,8 @@ struct hb_work_private_s hb_list_t * list; AVAudioResampleContext *avresample; + + int64_t last_pts; }; static int encavcodecaInit( hb_work_object_t *, hb_job_t * ); @@ -49,6 +51,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job) w->private_data = pv; pv->job = job; pv->list = hb_list_init(); + pv->last_pts = AV_NOPTS_VALUE; // channel count, layout and matrix encoding int matrix_encoding; @@ -363,17 +366,26 @@ static void get_packets( hb_work_object_t * w, hb_buffer_list_t * list ) out = hb_buffer_init(pkt.size); memcpy(out->data, pkt.data, out->size); - // The output pts from libav is in context->time_base. Convert it - // back to our timebase. - out->s.start = av_rescale_q(pkt.pts, pv->context->time_base, - (AVRational){1, 90000}); - out->s.duration = (double)90000 * pv->samples_per_frame / - audio->config.out.samplerate; - out->s.stop = out->s.start + out->s.duration; - out->s.type = AUDIO_BUF; - out->s.frametype = HB_FRAME_AUDIO; - - hb_buffer_list_append(list, out); + // FIXME: On windows builds, there is an upstream bug in the lame + // encoder that causes an extra output packet that has the same + // timestamp as the second to last packet. This causes an error + // during muxing. Work around it by dropping such packets here. + // See: https://github.com/HandBrake/HandBrake/issues/726 + if (pkt.pts > pv->last_pts) + { + // The output pts from libav is in context->time_base. Convert it + // back to our timebase. + out->s.start = av_rescale_q(pkt.pts, pv->context->time_base, + (AVRational){1, 90000}); + out->s.duration = (double)90000 * pv->samples_per_frame / + audio->config.out.samplerate; + out->s.stop = out->s.start + out->s.duration; + out->s.type = AUDIO_BUF; + out->s.frametype = HB_FRAME_AUDIO; + + hb_buffer_list_append(list, out); + pv->last_pts = pkt.pts; + } av_packet_unref(&pkt); } }