Web lists-archives.com

Re: [MPlayer-dev-eng] [PATCH]libmpdemux: Increase MAX_PACK_BYTES




On Wed, Mar 09, 2016 at 04:08:25PM +0000, Carl Eugen Hoyos wrote:
> Reimar Döffinger <Reimar.Doeffinger <at> gmx.de> writes:
> 
> > Ok, I probably found the cause for it, it looks like
> > FFmpeg and MPlayer disagree on when audio and video
> > are in sync and thus (from MPlayer's point of view)
> > not only interleaves rarely but actually interleaves
> > wrongly.
> > The file plays fine for me if I use
> > -speed 0.5 -delay -1
> 
> I can reproduce this but I suspect -delay -1 has 
> very bad effects, so there has to be a bug somewhere, 
> or am I wrong?

Maybe. It is very suspicious that a lot of the initial
audio packets all have a timestamp of 0, so maybe something
is wrong in the timestamps FFmpeg picks for them.
But if not, the file is simply horribly interleaved, with
video stored ahead of audio, causing the need to buffer
massive amount of video.
It could be worked around if the FFmpeg demuxer could be
force to return a audio packet next, but at these bit-rates
that probably would just lead to issues with I/O unless the
computer has several 100MB of RAM available to cache it all
(and maybe even then).
I have not checked if in the case of uncompressed audio
we maybe also read a bit too far ahead in the audio stream.
As a band-aid I would suggest expanding the meaning of
the -ni option to also cover this case, as in attached
patch.
diff --git a/help/help_mp-en.h b/help/help_mp-en.h
index 287f074..8d98113 100644
--- a/help/help_mp-en.h
+++ b/help/help_mp-en.h
@@ -1386,8 +1386,8 @@ static const char help_text[] = MSGTR_Help;
 #define MSGTR_VideoStreamRedefined "WARNING: Video stream header %d redefined.\n"
 #define MSGTR_TooManyAudioInBuffer "\nToo many audio packets in the buffer: (%d in %d bytes).\n"
 #define MSGTR_TooManyVideoInBuffer "\nToo many video packets in the buffer: (%d in %d bytes).\n"
-#define MSGTR_MaybeNI "Maybe you are playing a non-interleaved stream/file or the codec failed?\n" \
-                      "For AVI files, try to force non-interleaved mode with the -ni option.\n"
+#define MSGTR_MaybeNI "Maybe badly- or non-interleaved stream/file or the codec failed?\n" \
+                      "Fix the file or try the -ni option (can cause high memory usage).\n"
 #define MSGTR_WorkAroundBlockAlignHeaderBug "AVI: Working around CBR-MP3 nBlockAlign header bug!\n"
 #define MSGTR_SwitchToNi "\nBadly interleaved AVI file detected - switching to -ni mode...\n"
 #define MSGTR_InvalidAudioStreamNosound "AVI: invalid audio stream ID: %d - ignoring (nosound)\n"
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index 58f2c42..8430996 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -727,13 +727,13 @@ int ds_fill_buffer(demux_stream_t *ds)
         // avoid printing the "too many ..." message over and over
         if (ds->eof)
             break;
-        if (apacks >= MAX_PACKS || abytes >= MAX_PACK_BYTES) {
+        if (!force_ni && (apacks >= MAX_PACKS || abytes >= MAX_PACK_BYTES)) {
             mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyAudioInBuffer,
                    apacks, abytes);
             mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
             break;
         }
-        if (vpacks >= MAX_PACKS || vbytes >= MAX_PACK_BYTES) {
+        if (!force_ni && (vpacks >= MAX_PACKS || vbytes >= MAX_PACK_BYTES)) {
             mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyVideoInBuffer,
                    vpacks, vbytes);
             mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
@@ -941,15 +941,15 @@ double ds_get_next_pts(demux_stream_t *ds)
     // if we have not read from the "current" packet, consider it
     // as the next, otherwise we never get the pts for the first packet.
     while (!ds->first && (!ds->current || ds->buffer_pos)) {
-        if (demux->audio->packs >= MAX_PACKS
-            || demux->audio->bytes >= MAX_PACK_BYTES) {
+        if (!force_ni && (demux->audio->packs >= MAX_PACKS
+            || demux->audio->bytes >= MAX_PACK_BYTES)) {
             mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyAudioInBuffer,
                    demux->audio->packs, demux->audio->bytes);
             mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
             return MP_NOPTS_VALUE;
         }
-        if (demux->video->packs >= MAX_PACKS
-            || demux->video->bytes >= MAX_PACK_BYTES) {
+        if (!force_ni && (demux->video->packs >= MAX_PACKS
+            || demux->video->bytes >= MAX_PACK_BYTES)) {
             mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyVideoInBuffer,
                    demux->video->packs, demux->video->bytes);
             mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng