# HG changeset patch # User ranma # Date 1309100151 0 # Node ID 4c3bee76ef3bd8bdde804608f35d784b72adda9d # Parent c15dabfa23804de3ac6742468e80defac9c63187 The muxer prebuffers packets until each stream has been seen so a proper header can be written. However if mencoder inserts "repeat last frame" chunks with len == 0 before the encoder is configured and first real frame is output or a broken file starts a stream with such frames, then muxer won't find needed info for writing initial header. diff -r c15dabfa2380 -r 4c3bee76ef3b libmpdemux/muxer.c --- a/libmpdemux/muxer.c Sun Jun 26 14:42:35 2011 +0000 +++ b/libmpdemux/muxer.c Sun Jun 26 14:55:51 2011 +0000 @@ -121,7 +121,7 @@ } /* buffer frames until we either: - * (a) have at least one frame from each stream + * (a) have at least one non-empty frame from each stream * (b) run out of memory */ void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts) { if(dts == MP_NOPTS_VALUE) dts= s->timer; @@ -154,7 +154,14 @@ return; } memcpy(buf->buffer, s->buffer, buf->len); - s->muxbuf_seen = 1; + + /* If mencoder inserts "repeat last frame" chunks with len == 0 + * before the encoder is configured and first real frame is output + * or a broken file starts a stream with such frames, then muxer + * won't find needed info for writing initial header. + * Wait until the first real frame is seen. */ + if (len > 0) + s->muxbuf_seen = 1; /* see if we need to keep buffering */ s->muxer->muxbuf_skip_buffer = 1;