diff options
author | John Stebbins <[email protected]> | 2017-05-11 13:17:51 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2017-05-11 13:19:40 -0700 |
commit | 7f17f5c08129a39da12352828d6ec145dc448261 (patch) | |
tree | e13e507bd4b0ab87618050c6849962f040b776db /libhb | |
parent | ec57a237454d198768b82985a7daa06d9c4abd17 (diff) |
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
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/encavcodecaudio.c | 34 |
1 files changed, 23 insertions, 11 deletions
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); } } |