On Sun, May 4, 2014 at 11:55 PM, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
Yes, after you pointed out how it works I think it kind of is. I do think it's less obvious than it should be though, and I am not sure it doesn't have issues like flushing the encoder buffer even on decode errors instead of EOF plus I suspect the same hang bug exists in certain -oac copy cases which this patch won't fix since it only affects the encoding case.
Okay, here is a second attempt at a patch. It's a bit longer this time, but tidies up a few things, is more thorough about checking EOF (at least as thorough as the rest of the code is) and fixes any issues with other encode paths. I have added a 'bytes_ready' variable so that there is less confusion with the 'len' variable which is now just used for the decode length not the encode length. Patch description below. --- Changes to mencoder introduced by r36905 (2014-02-24; mencoder: Finish encoding only when audio and video reached EOF.) introduced a regression when using mp3lame and possibly other audio encoders. This was first reported by Alexander Roalter on mplayer-users: https://lists.mplayerhq.hu/pipermail/mplayer-users/2014-March/087288.html $ mencoder -msglevel all=6 -o out.avi -oac mp3lame -ovc lavc input ... (works normally until the end of the audio stream, but after the end of the video stream, an endless loop of messages begins:) ... ds_fill_buffer: EOF reached (stream: audio) ds_fill_buffer: EOF reached (stream: video) ds_fill_buffer: EOF reached (stream: audio) ds_fill_buffer: EOF reached (stream: video) ... 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. This patch checks mux_a->buffer_len and ensures any remaining data is muxed. This patch also adds a new variable 'bytes_ready' to avoid using the same variable for both the number of decoded bytes AND encoded bytes. Kieran Clancy --- mencoder.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-)