diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index cb8e24d4aa..974d9c5faa 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -164,8 +164,10 @@ static int init(struct ao *ao) } // close audio device +static int encode(struct ao *ao, double apts, void **data); static void uninit(struct ao *ao, bool cut_audio) { + struct priv *ac = ao->priv; struct encode_lavc_context *ectx = ao->encode_lavc_ctx; if (!encode_lavc_start(ectx)) { @@ -173,6 +175,14 @@ static void uninit(struct ao *ao, bool cut_audio) return; } + if (ac->buffer) { + double outpts = ac->expected_next_pts; + if (!ectx->options->rawts && ectx->options->copyts) + outpts += ectx->discontinuity_pts_offset; + outpts += encode_lavc_getoffset(ectx, ac->stream); + while (encode(ao, outpts, NULL) > 0) ; + } + ao->priv = NULL; } @@ -332,13 +342,6 @@ static int play(struct ao *ao, void **data, int samples, int flags) talloc_free(tmp); } - outpts = ac->expected_next_pts; - if (!ectx->options->rawts && ectx->options->copyts) - outpts += ectx->discontinuity_pts_offset; - outpts += encode_lavc_getoffset(ectx, ac->stream); - - while (encode(ao, outpts, NULL) > 0) ; - return FFMIN(written, samples); }