Browse code

avformat/mpegenc: Ignore max_delay if no other options remain

Fixes assertion failure
Fixes Ticket4335

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

Michael Niedermayer authored on 2015/03/02 00:47:36
Showing 1 changed files
... ...
@@ -960,6 +960,7 @@ static int output_packet(AVFormatContext *ctx, int flush)
960 960
     int best_i = -1;
961 961
     int best_score = INT_MIN;
962 962
     int ignore_constraints = 0;
963
+    int ignore_delay = 0;
963 964
     int64_t scr = s->last_scr;
964 965
     PacketDesc *timestamp_packet;
965 966
     const int64_t max_delay = av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
... ...
@@ -985,7 +986,7 @@ retry:
985 985
         if (space < s->packet_size && !ignore_constraints)
986 986
             continue;
987 987
 
988
-        if (next_pkt && next_pkt->dts - scr > max_delay)
988
+        if (next_pkt && next_pkt->dts - scr > max_delay && !ignore_delay)
989 989
             continue;
990 990
         if (   stream->predecode_packet
991 991
             && stream->predecode_packet->size > stream->buffer_index)
... ...
@@ -999,6 +1000,7 @@ retry:
999 999
 
1000 1000
     if (best_i < 0) {
1001 1001
         int64_t best_dts = INT64_MAX;
1002
+        int has_premux = 0;
1002 1003
 
1003 1004
         for (i = 0; i < ctx->nb_streams; i++) {
1004 1005
             AVStream *st = ctx->streams[i];
... ...
@@ -1006,21 +1008,29 @@ retry:
1006 1006
             PacketDesc *pkt_desc = stream->predecode_packet;
1007 1007
             if (pkt_desc && pkt_desc->dts < best_dts)
1008 1008
                 best_dts = pkt_desc->dts;
1009
+            has_premux |= !!stream->premux_packet;
1009 1010
         }
1010 1011
 
1011
-        av_dlog(ctx, "bumping scr, scr:%f, dts:%f\n",
1012
-                scr / 90000.0, best_dts / 90000.0);
1013
-        if (best_dts == INT64_MAX)
1014
-            return 0;
1012
+        if (best_dts < INT64_MAX) {
1013
+            av_dlog(ctx, "bumping scr, scr:%f, dts:%f\n",
1014
+                    scr / 90000.0, best_dts / 90000.0);
1015 1015
 
1016
-        if (scr >= best_dts + 1 && !ignore_constraints) {
1016
+            if (scr >= best_dts + 1 && !ignore_constraints) {
1017
+                av_log(ctx, AV_LOG_ERROR,
1018
+                    "packet too large, ignoring buffer limits to mux it\n");
1019
+                ignore_constraints = 1;
1020
+            }
1021
+            scr = FFMAX(best_dts + 1, scr);
1022
+            if (remove_decoded_packets(ctx, scr) < 0)
1023
+                return -1;
1024
+        } else if (has_premux && flush) {
1017 1025
             av_log(ctx, AV_LOG_ERROR,
1018
-                   "packet too large, ignoring buffer limits to mux it\n");
1026
+                  "delay too large, ignoring ...\n");
1027
+            ignore_delay = 1;
1019 1028
             ignore_constraints = 1;
1020
-        }
1021
-        scr = FFMAX(best_dts + 1, scr);
1022
-        if (remove_decoded_packets(ctx, scr) < 0)
1023
-            return -1;
1029
+        } else
1030
+            return 0;
1031
+
1024 1032
         goto retry;
1025 1033
     }
1026 1034