Web lists-archives.com

Re: [MPlayer-dev-eng] [PATCH] mencoder: detect end of audio stream while encoded data still buffered




On Mon, May 05, 2014 at 11:58:27PM +0930, Kieran Clancy wrote:
> After running a debugger, I found the problem is that for some VBR
> codecs like mp3lame, mux_a->buffer_len is not always zero on
> end-of-stream.

What exactly do you mean by "for some"?
For mp3lame it is this crappy workaround in ae_lame.c that should cause it:
mux_a->wf->nBlockAlign=encoder->params.samples_per_frame; // required for l3codeca.acm + WMP 6.4

I would hope we have no such hacks for all others.

> This patch checks mux_a->buffer_len and ensures any remaining data is muxed.

Any reason to not just do it like attached patch?
diff --git a/mencoder.c b/mencoder.c
index 671d4c2..583fc95 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -1390,7 +1390,7 @@ if(sh_audio){
 		}
 	    }
 	}
-	if(len<=0) { if (!mux_a->buffer_len && !sh_audio->a_out_buffer_len && sh_audio->ds->eof) at_eof |= 2; break; } // EOF?
+	if(len<=0) { if (!sh_audio->a_out_buffer_len && sh_audio->ds->eof) at_eof |= 2; break; } // EOF?
 	muxer_write_chunk(mux_a,len,AVIIF_KEYFRAME, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
 	a_muxer_time = adjusted_muxer_time(mux_a); // update after muxing
 	if(!mux_a->h.dwSampleSize && a_muxer_time>0)
@@ -1686,6 +1686,12 @@ if(sh_video && sh_video->vfilter){
     	                                              VFCTRL_FLUSH_FRAMES, 0);
 }
 
+if (mux_a->buffer_len > 0) {
+	mp_msg(MSGT_MENCODER, MSGL_WARN, "Writing out %d bytes of left-over audio data.", mux_a->buffer_len);
+	muxer_write_chunk(mux_a,mux_a->buffer_len,AVIIF_KEYFRAME, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
+	mux_a->buffer_len = 0;
+}
+
 if(aencoder)
     if(aencoder->fixup)
         aencoder->fixup(aencoder);
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng