]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/nutenc.c
swr/resample_template: prevent end_index from overflowing and add check for delta_fra...
[ffmpeg] / libavformat / nutenc.c
index 74ba1e8d5a643b9847a2d78067543f76fbc78843..dfe0a32d5e1f3ffbbfb30848560183503c604abd 100644 (file)
@@ -965,6 +965,8 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
         av_log(s, AV_LOG_ERROR,
                "Negative pts not supported stream %d, pts %"PRId64"\n",
                pkt->stream_index, pkt->pts);
+        if (pkt->pts == AV_NOPTS_VALUE)
+            av_log(s, AV_LOG_ERROR, "Try to enable the genpts flag\n");
         return AVERROR(EINVAL);
     }
 
@@ -1002,8 +1004,15 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
                 AV_ROUND_DOWN);
             int index = av_index_search_timestamp(st, dts_tb,
                                                   AVSEEK_FLAG_BACKWARD);
-            if (index >= 0)
+            if (index >= 0) {
                 sp_pos = FFMIN(sp_pos, st->index_entries[index].pos);
+                if (!nut->write_index && 2*index > st->nb_index_entries) {
+                    memmove(st->index_entries,
+                            st->index_entries + index,
+                            sizeof(*st->index_entries) * (st->nb_index_entries - index));
+                    st->nb_index_entries -=  index;
+                }
+            }
         }
 
         nut->last_syncpoint_pos = avio_tell(bc);
@@ -1019,6 +1028,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
         }
         put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
 
+        if (nut->write_index) {
         if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/, pkt->dts)) < 0)
             return ret;
 
@@ -1032,6 +1042,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
                 for (j=nut->sp_count == 1 ? 0 : nut->sp_count; j<2*nut->sp_count; j++)
                     nus->keyframe_pts[j] = AV_NOPTS_VALUE;
         }
+        }
     }
     av_assert0(nus->last_pts != AV_NOPTS_VALUE);
 
@@ -1158,6 +1169,7 @@ static int nut_write_trailer(AVFormatContext *s)
 
     ret = avio_open_dyn_buf(&dyn_bc);
     if (ret >= 0 && nut->sp_count) {
+        av_assert1(nut->write_index);
         write_index(nut, dyn_bc);
         put_packet(nut, bc, dyn_bc, 1, INDEX_STARTCODE);
     }
@@ -1180,6 +1192,7 @@ static const AVOption options[] = {
     { "default",     "",                                                0,             AV_OPT_TYPE_CONST, {.i64 = 0},             INT_MIN, INT_MAX, E, "syncpoints" },
     { "none",        "Disable syncpoints, low overhead and unseekable", 0,             AV_OPT_TYPE_CONST, {.i64 = NUT_PIPE},      INT_MIN, INT_MAX, E, "syncpoints" },
     { "timestamped", "Extend syncpoints with a wallclock timestamp",    0,             AV_OPT_TYPE_CONST, {.i64 = NUT_BROADCAST}, INT_MIN, INT_MAX, E, "syncpoints" },
+    { "write_index", "Write index",                               OFFSET(write_index), AV_OPT_TYPE_INT,   {.i64 = 1},                   0,       1, E, },
     { NULL },
 };