Browse code

avformat/nutenc: add mode that omits the index

When the index is not written, several data tables become unneeded,
reducing memory and cpu requirements.

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

Michael Niedermayer authored on 2014/05/29 10:32:44
Showing 3 changed files
... ...
@@ -717,6 +717,8 @@ Change the syncpoint usage in nut:
717 717
 @item @var{timestamped} extend the syncpoint with a wallclock field.
718 718
 @end table
719 719
 The @var{none} and @var{timestamped} flags are experimental.
720
+@item -write_index @var{bool}
721
+Write index at the end, the default is to write an index.
720 722
 @end table
721 723
 
722 724
 @example
... ...
@@ -106,6 +106,7 @@ typedef struct NUTContext {
106 106
     AVRational *time_base;
107 107
     struct AVTreeNode *syncpoints;
108 108
     int sp_count;
109
+    int write_index;
109 110
     int64_t max_pts;
110 111
     AVRational *max_pts_tb;
111 112
 #define NUT_BROADCAST 1 // use extended syncpoints
... ...
@@ -1019,6 +1019,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
1019 1019
         }
1020 1020
         put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
1021 1021
 
1022
+        if (nut->write_index) {
1022 1023
         if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/, pkt->dts)) < 0)
1023 1024
             return ret;
1024 1025
 
... ...
@@ -1032,6 +1033,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
1032 1032
                 for (j=nut->sp_count == 1 ? 0 : nut->sp_count; j<2*nut->sp_count; j++)
1033 1033
                     nus->keyframe_pts[j] = AV_NOPTS_VALUE;
1034 1034
         }
1035
+        }
1035 1036
     }
1036 1037
     av_assert0(nus->last_pts != AV_NOPTS_VALUE);
1037 1038
 
... ...
@@ -1157,7 +1159,7 @@ static int nut_write_trailer(AVFormatContext *s)
1157 1157
         write_headers(s, bc);
1158 1158
 
1159 1159
     ret = avio_open_dyn_buf(&dyn_bc);
1160
-    if (ret >= 0 && nut->sp_count) {
1160
+    if (ret >= 0 && nut->sp_count && nut->write_index) {
1161 1161
         write_index(nut, dyn_bc);
1162 1162
         put_packet(nut, bc, dyn_bc, 1, INDEX_STARTCODE);
1163 1163
     }
... ...
@@ -1180,6 +1182,7 @@ static const AVOption options[] = {
1180 1180
     { "default",     "",                                                0,             AV_OPT_TYPE_CONST, {.i64 = 0},             INT_MIN, INT_MAX, E, "syncpoints" },
1181 1181
     { "none",        "Disable syncpoints, low overhead and unseekable", 0,             AV_OPT_TYPE_CONST, {.i64 = NUT_PIPE},      INT_MIN, INT_MAX, E, "syncpoints" },
1182 1182
     { "timestamped", "Extend syncpoints with a wallclock timestamp",    0,             AV_OPT_TYPE_CONST, {.i64 = NUT_BROADCAST}, INT_MIN, INT_MAX, E, "syncpoints" },
1183
+    { "write_index", "Write index",                               OFFSET(write_index), AV_OPT_TYPE_INT,   {.i64 = 1},                   0,       1, E, },
1183 1184
     { NULL },
1184 1185
 };
1185 1186