Mercurial > mplayer.hg
changeset 37099:5a59a2cfcc80
mencoder: Support flushing audio encoders at end of stream.
author | reimar |
---|---|
date | Sat, 10 May 2014 19:59:40 +0000 |
parents | 5674877e6814 |
children | 3466f03a5256 |
files | libmpcodecs/ae_lame.c libmpcodecs/ae_twolame.c mencoder.c |
diffstat | 3 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpcodecs/ae_lame.c Sat May 10 19:59:38 2014 +0000 +++ b/libmpcodecs/ae_lame.c Sat May 10 19:59:40 2014 +0000 @@ -136,7 +136,9 @@ static int encode_lame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) { int n = 0; - if(encoder->params.channels == 1) + if (!src) + n = lame_encode_flush(lame, dest, max_size); + else if (encoder->params.channels == 1) n = lame_encode_buffer(lame, (short *)src, (short *)src, len/2, dest, max_size); else n = lame_encode_buffer_interleaved(lame,(short *)src, len/4, dest, max_size);
--- a/libmpcodecs/ae_twolame.c Sat May 10 19:59:38 2014 +0000 +++ b/libmpcodecs/ae_twolame.c Sat May 10 19:59:40 2014 +0000 @@ -112,6 +112,9 @@ mpae_twolame_ctx *ctx = encoder->priv; int ret_size = 0, r2; + if (!src) + return twolame_encode_flush(ctx->twolame_ctx, dest, max_size); + len /= (2*encoder->params.channels); ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size); r2 = mp_decode_mp3_header(dest);
--- a/mencoder.c Sat May 10 19:59:38 2014 +0000 +++ b/mencoder.c Sat May 10 19:59:40 2014 +0000 @@ -1340,7 +1340,7 @@ len = dec_audio(sh_audio, aencoder->decode_buffer, len); mux_a->buffer_len += aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, - aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len); + len <= 0 && sh_audio->ds->eof ? NULL : aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len); if(mux_a->buffer_len < mux_a->wf->nBlockAlign) len = 0; else @@ -1362,10 +1362,13 @@ len = dec_audio(sh_audio,aencoder->decode_buffer, aencoder->decode_buffer_size); if(len <= 0) { - len = 0; - break; - } - len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len); + // try flushing encoder + if (sh_audio->ds->eof) + len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, NULL, 0, mux_a->buffer_size-mux_a->buffer_len); + if (len <= 0) + break; + } else + len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len); mux_a->buffer_len += len; } }