[FFmpeg-cvslog] avformat/mpegenc: Ignore max_delay if no other options remain

Michael Niedermayer git at videolan.org
Sun Mar 1 17:00:13 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Mar  1 16:47:36 2015 +0100| [e72f8ceabde3daa673d7c46bd1d13bf9594e2c40] | committer: Michael Niedermayer

avformat/mpegenc: Ignore max_delay if no other options remain

Fixes assertion failure
Fixes Ticket4335

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e72f8ceabde3daa673d7c46bd1d13bf9594e2c40
---

 libavformat/mpegenc.c |   32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 9cee967..b1b59ed 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -960,6 +960,7 @@ static int output_packet(AVFormatContext *ctx, int flush)
     int best_i = -1;
     int best_score = INT_MIN;
     int ignore_constraints = 0;
+    int ignore_delay = 0;
     int64_t scr = s->last_scr;
     PacketDesc *timestamp_packet;
     const int64_t max_delay = av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
@@ -985,7 +986,7 @@ retry:
         if (space < s->packet_size && !ignore_constraints)
             continue;
 
-        if (next_pkt && next_pkt->dts - scr > max_delay)
+        if (next_pkt && next_pkt->dts - scr > max_delay && !ignore_delay)
             continue;
         if (   stream->predecode_packet
             && stream->predecode_packet->size > stream->buffer_index)
@@ -999,6 +1000,7 @@ retry:
 
     if (best_i < 0) {
         int64_t best_dts = INT64_MAX;
+        int has_premux = 0;
 
         for (i = 0; i < ctx->nb_streams; i++) {
             AVStream *st = ctx->streams[i];
@@ -1006,21 +1008,29 @@ retry:
             PacketDesc *pkt_desc = stream->predecode_packet;
             if (pkt_desc && pkt_desc->dts < best_dts)
                 best_dts = pkt_desc->dts;
+            has_premux |= !!stream->premux_packet;
         }
 
-        av_dlog(ctx, "bumping scr, scr:%f, dts:%f\n",
-                scr / 90000.0, best_dts / 90000.0);
-        if (best_dts == INT64_MAX)
-            return 0;
+        if (best_dts < INT64_MAX) {
+            av_dlog(ctx, "bumping scr, scr:%f, dts:%f\n",
+                    scr / 90000.0, best_dts / 90000.0);
 
-        if (scr >= best_dts + 1 && !ignore_constraints) {
+            if (scr >= best_dts + 1 && !ignore_constraints) {
+                av_log(ctx, AV_LOG_ERROR,
+                    "packet too large, ignoring buffer limits to mux it\n");
+                ignore_constraints = 1;
+            }
+            scr = FFMAX(best_dts + 1, scr);
+            if (remove_decoded_packets(ctx, scr) < 0)
+                return -1;
+        } else if (has_premux && flush) {
             av_log(ctx, AV_LOG_ERROR,
-                   "packet too large, ignoring buffer limits to mux it\n");
+                  "delay too large, ignoring ...\n");
+            ignore_delay = 1;
             ignore_constraints = 1;
-        }
-        scr = FFMAX(best_dts + 1, scr);
-        if (remove_decoded_packets(ctx, scr) < 0)
-            return -1;
+        } else
+            return 0;
+
         goto retry;
     }
 



More information about the ffmpeg-cvslog mailing list