diff mbox series

[FFmpeg-devel] Revert "lavf: move AVStream.*index_entries* to AVStreamInternal"

Message ID 20210322144840.54428-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] Revert "lavf: move AVStream.*index_entries* to AVStreamInternal" | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer March 22, 2021, 2:48 p.m. UTC
This reverts commit cea7c19cda0ea1630ae1de8c102ab14231b9db10.

Until an API is added to make index_entries public in a proper way, we should
keep this here.

Signed-off-by: James Almer <jamrial@gmail.com>
---
Some library users looked at these fields since they are apparently pretty
useful, so at least for 4.4 we should keep them in place, even if not
technically public, since doing so is harmless and less disruptive for users
upgrading from 4.3.
We should then come up with a proper method to retrieve this information for
the next release, even if said method is simply making these fields officially
public.

 libavformat/ape.c         |   2 +-
 libavformat/asfdec_f.c    |   4 +-
 libavformat/asfdec_o.c    |   6 +-
 libavformat/avformat.h    |   7 +-
 libavformat/avidec.c      | 100 ++++++++++----------
 libavformat/bink.c        |  10 +-
 libavformat/cafdec.c      |  22 ++---
 libavformat/cinedec.c     |   4 +-
 libavformat/dhav.c        |   4 +-
 libavformat/flacdec.c     |   8 +-
 libavformat/flic.c        |   6 +-
 libavformat/flvdec.c      |  10 +-
 libavformat/gxf.c         |   6 +-
 libavformat/ifv.c         |   8 +-
 libavformat/img2dec.c     |   2 +-
 libavformat/internal.h    |   5 -
 libavformat/jvdec.c       |  28 +++---
 libavformat/matroskadec.c |  40 ++++----
 libavformat/mlvdec.c      |  20 ++--
 libavformat/mov.c         | 194 +++++++++++++++++++-------------------
 libavformat/mp3dec.c      |   6 +-
 libavformat/mpc.c         |   4 +-
 libavformat/mpc8.c        |   4 +-
 libavformat/mux.c         |   2 +-
 libavformat/mvdec.c       |   4 +-
 libavformat/nsvdec.c      |   4 +-
 libavformat/nutdec.c      |   6 +-
 libavformat/nutenc.c      |  12 +--
 libavformat/rl2.c         |   8 +-
 libavformat/rpl.c         |   4 +-
 libavformat/segafilm.c    |   2 +-
 libavformat/tta.c         |   8 +-
 libavformat/utils.c       |  46 ++++-----
 libavformat/vocdec.c      |   8 +-
 34 files changed, 300 insertions(+), 304 deletions(-)

Comments

James Almer March 22, 2021, 2:51 p.m. UTC | #1
On 3/22/2021 11:48 AM, James Almer wrote:
> This reverts commit cea7c19cda0ea1630ae1de8c102ab14231b9db10.
> 
> Until an API is added to make index_entries public in a proper way, we should
> keep this here.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> Some library users looked at these fields since they are apparently pretty
> useful, so at least for 4.4 we should keep them in place, even if not
> technically public, since doing so is harmless and less disruptive for users
> upgrading from 4.3.
> We should then come up with a proper method to retrieve this information for
> the next release, even if said method is simply making these fields officially
> public.

To be more specific in case it wasn't clear, this revert is meant only 
for 4.4. Master is fine as is and where we should introduce the proper API.
James Almer March 23, 2021, 4:45 p.m. UTC | #2
On 3/22/2021 11:51 AM, James Almer wrote:
> On 3/22/2021 11:48 AM, James Almer wrote:
>> This reverts commit cea7c19cda0ea1630ae1de8c102ab14231b9db10.
>>
>> Until an API is added to make index_entries public in a proper way, we 
>> should
>> keep this here.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> Some library users looked at these fields since they are apparently 
>> pretty
>> useful, so at least for 4.4 we should keep them in place, even if not
>> technically public, since doing so is harmless and less disruptive for 
>> users
>> upgrading from 4.3.
>> We should then come up with a proper method to retrieve this 
>> information for
>> the next release, even if said method is simply making these fields 
>> officially
>> public.
> 
> To be more specific in case it wasn't clear, this revert is meant only 
> for 4.4. Master is fine as is and where we should introduce the proper API.

Will apply.
diff mbox series

Patch

diff --git a/libavformat/ape.c b/libavformat/ape.c
index 4c161235fe..2698c770ee 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -444,7 +444,7 @@  static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
     if (index < 0)
         return -1;
 
-    if ((ret = avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET)) < 0)
+    if ((ret = avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET)) < 0)
         return ret;
     ape->currentframe = index;
     return 0;
diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
index 1484b544d9..f784e62996 100644
--- a/libavformat/asfdec_f.c
+++ b/libavformat/asfdec_f.c
@@ -1690,11 +1690,11 @@  static int asf_read_seek(AVFormatContext *s, int stream_index,
             asf->index_read = -1;
     }
 
-    if (asf->index_read > 0 && st->internal->index_entries) {
+    if (asf->index_read > 0 && st->index_entries) {
         int index = av_index_search_timestamp(st, pts, flags);
         if (index >= 0) {
             /* find the position */
-            uint64_t pos = st->internal->index_entries[index].pos;
+            uint64_t pos = st->index_entries[index].pos;
 
             /* do the seek */
             av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
index 34ae541934..7c08565180 100644
--- a/libavformat/asfdec_o.c
+++ b/libavformat/asfdec_o.c
@@ -1636,11 +1636,11 @@  static int asf_read_seek(AVFormatContext *s, int stream_index,
     ASFContext *asf = s->priv_data;
     int idx, ret;
 
-    if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) {
+    if (s->streams[stream_index]->nb_index_entries && asf->is_simple_index) {
         idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags);
-        if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries)
+        if (idx < 0 || idx >= s->streams[stream_index]->nb_index_entries)
             return AVERROR_INVALIDDATA;
-        avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET);
+        avio_seek(s->pb, s->streams[stream_index]->index_entries[idx].pos, SEEK_SET);
     } else {
         if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0)
             return ret;
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 765bc3b6f5..56708c0241 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1088,10 +1088,11 @@  typedef struct AVStream {
     void        *unused7;
     AVProbeData  unused6;
     int64_t      unused5[16+1];
-    void         *unused2;
-    int          unused3;
-    unsigned int unused4;
 #endif
+    AVIndexEntry *index_entries; /**< Only used if the format does not
+                                    support seeking natively. */
+    int nb_index_entries;
+    unsigned int index_entries_allocated_size;
 
     /**
      * Stream Identifier
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index fa0599501a..ed1e5b78d0 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -281,7 +281,7 @@  static void clean_index(AVFormatContext *s)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st   = s->streams[i];
         AVIStream *ast = st->priv_data;
-        int n          = st->internal->nb_index_entries;
+        int n          = st->nb_index_entries;
         int max        = ast->sample_size;
         int64_t pos, size, ts;
 
@@ -291,9 +291,9 @@  static void clean_index(AVFormatContext *s)
         while (max < 1024)
             max += max;
 
-        pos  = st->internal->index_entries[0].pos;
-        size = st->internal->index_entries[0].size;
-        ts   = st->internal->index_entries[0].timestamp;
+        pos  = st->index_entries[0].pos;
+        size = st->index_entries[0].size;
+        ts   = st->index_entries[0].timestamp;
 
         for (j = 0; j < size; j += max)
             av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0,
@@ -441,12 +441,12 @@  static int calculate_bitrate(AVFormatContext *s)
         int64_t len = 0;
         AVStream *st = s->streams[i];
 
-        if (!st->internal->nb_index_entries)
+        if (!st->nb_index_entries)
             continue;
 
-        for (j = 0; j < st->internal->nb_index_entries; j++)
-            len += st->internal->index_entries[j].size;
-        maxpos = FFMAX(maxpos, st->internal->index_entries[j-1].pos);
+        for (j = 0; j < st->nb_index_entries; j++)
+            len += st->index_entries[j].size;
+        maxpos = FFMAX(maxpos, st->index_entries[j-1].pos);
         lensum += len;
     }
     if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file
@@ -460,12 +460,12 @@  static int calculate_bitrate(AVFormatContext *s)
         int64_t duration;
         int64_t bitrate;
 
-        for (j = 0; j < st->internal->nb_index_entries; j++)
-            len += st->internal->index_entries[j].size;
+        for (j = 0; j < st->nb_index_entries; j++)
+            len += st->index_entries[j].size;
 
-        if (st->internal->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
+        if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
             continue;
-        duration = st->internal->index_entries[j-1].timestamp - st->internal->index_entries[0].timestamp;
+        duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp;
         bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num);
         if (bitrate > 0) {
             st->codecpar->bit_rate = bitrate;
@@ -1057,7 +1057,7 @@  end_of_header:
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-        if (st->internal->nb_index_entries)
+        if (st->nb_index_entries)
             break;
     }
     // DV-in-AVI cannot be non-interleaved, if set this must be
@@ -1347,8 +1347,8 @@  start_sync:
 
                 if (size) {
                     uint64_t pos = avio_tell(pb) - 8;
-                    if (!st->internal->index_entries || !st->internal->nb_index_entries ||
-                        st->internal->index_entries[st->internal->nb_index_entries - 1].pos < pos) {
+                    if (!st->index_entries || !st->nb_index_entries ||
+                        st->index_entries[st->nb_index_entries - 1].pos < pos) {
                         av_add_index_entry(st, pos, ast->frame_offset, size,
                                            0, AVINDEX_KEYFRAME);
                     }
@@ -1378,10 +1378,10 @@  static int ni_prepare_read(AVFormatContext *s)
         int64_t ts     = ast->frame_offset;
         int64_t last_ts;
 
-        if (!st->internal->nb_index_entries)
+        if (!st->nb_index_entries)
             continue;
 
-        last_ts = st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp;
+        last_ts = st->index_entries[st->nb_index_entries - 1].timestamp;
         if (!ast->remaining && ts > last_ts)
             continue;
 
@@ -1410,11 +1410,11 @@  static int ni_prepare_read(AVFormatContext *s)
     } else {
         i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
         if (i >= 0)
-            best_ast->frame_offset = best_st->internal->index_entries[i].timestamp;
+            best_ast->frame_offset = best_st->index_entries[i].timestamp;
     }
 
     if (i >= 0) {
-        int64_t pos = best_st->internal->index_entries[i].pos;
+        int64_t pos = best_st->index_entries[i].pos;
         pos += best_ast->packet_size - best_ast->remaining;
         if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
           return AVERROR_EOF;
@@ -1424,7 +1424,7 @@  static int ni_prepare_read(AVFormatContext *s)
         avi->stream_index = best_stream_index;
         if (!best_ast->remaining)
             best_ast->packet_size =
-            best_ast->remaining   = best_st->internal->index_entries[i].size;
+            best_ast->remaining   = best_st->index_entries[i].size;
     }
     else
         return AVERROR_EOF;
@@ -1515,15 +1515,15 @@  resync:
                 pkt->dts /= ast->sample_size;
             pkt->stream_index = avi->stream_index;
 
-            if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->index_entries) {
+            if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) {
                 AVIndexEntry *e;
                 int index;
 
                 index = av_index_search_timestamp(st, ast->frame_offset, AVSEEK_FLAG_ANY);
-                e     = &st->internal->index_entries[index];
+                e     = &st->index_entries[index];
 
                 if (index >= 0 && e->timestamp == ast->frame_offset) {
-                    if (index == st->internal->nb_index_entries-1) {
+                    if (index == st->nb_index_entries-1) {
                         int key=1;
                         uint32_t state=-1;
                         if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
@@ -1559,7 +1559,7 @@  resync:
         }
         ast->seek_pos= 0;
 
-        if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) {
+        if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) {
             int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
 
             if (avi->dts_max < dts) {
@@ -1659,8 +1659,8 @@  static int avi_read_idx1(AVFormatContext *s, int size)
     if (!anykey) {
         for (index = 0; index < s->nb_streams; index++) {
             st = s->streams[index];
-            if (st->internal->nb_index_entries)
-                st->internal->index_entries[0].flags |= AVINDEX_KEYFRAME;
+            if (st->nb_index_entries)
+                st->index_entries[0].flags |= AVINDEX_KEYFRAME;
         }
     }
     return 0;
@@ -1685,16 +1685,16 @@  static int check_stream_max_drift(AVFormatContext *s)
         for (i = 0; i < s->nb_streams; i++) {
             AVStream *st = s->streams[i];
             AVIStream *ast = st->priv_data;
-            int n = st->internal->nb_index_entries;
-            while (idx[i] < n && st->internal->index_entries[idx[i]].pos < pos)
+            int n = st->nb_index_entries;
+            while (idx[i] < n && st->index_entries[idx[i]].pos < pos)
                 idx[i]++;
             if (idx[i] < n) {
                 int64_t dts;
-                dts = av_rescale_q(st->internal->index_entries[idx[i]].timestamp /
+                dts = av_rescale_q(st->index_entries[idx[i]].timestamp /
                                    FFMAX(ast->sample_size, 1),
                                    st->time_base, AV_TIME_BASE_Q);
                 min_dts = FFMIN(min_dts, dts);
-                min_pos = FFMIN(min_pos, st->internal->index_entries[idx[i]].pos);
+                min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos);
             }
         }
         for (i = 0; i < s->nb_streams; i++) {
@@ -1703,7 +1703,7 @@  static int check_stream_max_drift(AVFormatContext *s)
 
             if (idx[i] && min_dts != INT64_MAX / 2) {
                 int64_t dts, delta_dts;
-                dts = av_rescale_q(st->internal->index_entries[idx[i] - 1].timestamp /
+                dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp /
                                    FFMAX(ast->sample_size, 1),
                                    st->time_base, AV_TIME_BASE_Q);
                 delta_dts = av_sat_sub64(dts, min_dts);
@@ -1733,30 +1733,30 @@  static int guess_ni_flag(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-        int n        = st->internal->nb_index_entries;
+        int n        = st->nb_index_entries;
         unsigned int size;
 
         if (n <= 0)
             continue;
 
         if (n >= 2) {
-            int64_t pos = st->internal->index_entries[0].pos;
+            int64_t pos = st->index_entries[0].pos;
             unsigned tag[2];
             avio_seek(s->pb, pos, SEEK_SET);
             tag[0] = avio_r8(s->pb);
             tag[1] = avio_r8(s->pb);
             avio_rl16(s->pb);
             size = avio_rl32(s->pb);
-            if (get_stream_idx(tag) == i && pos + size > st->internal->index_entries[1].pos)
+            if (get_stream_idx(tag) == i && pos + size > st->index_entries[1].pos)
                 last_start = INT64_MAX;
-            if (get_stream_idx(tag) == i && size == st->internal->index_entries[0].size + 8)
+            if (get_stream_idx(tag) == i && size == st->index_entries[0].size + 8)
                 last_start = INT64_MAX;
         }
 
-        if (st->internal->index_entries[0].pos > last_start)
-            last_start = st->internal->index_entries[0].pos;
-        if (st->internal->index_entries[n - 1].pos < first_end)
-            first_end = st->internal->index_entries[n - 1].pos;
+        if (st->index_entries[0].pos > last_start)
+            last_start = st->index_entries[0].pos;
+        if (st->index_entries[n - 1].pos < first_end)
+            first_end = st->index_entries[n - 1].pos;
     }
     avio_seek(s->pb, oldpos, SEEK_SET);
 
@@ -1844,20 +1844,20 @@  static int avi_read_seek(AVFormatContext *s, int stream_index,
                                       timestamp * FFMAX(ast->sample_size, 1),
                                       flags);
     if (index < 0) {
-        if (st->internal->nb_index_entries > 0)
+        if (st->nb_index_entries > 0)
             av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
                    timestamp * FFMAX(ast->sample_size, 1),
-                   st->internal->index_entries[0].timestamp,
-                   st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp);
+                   st->index_entries[0].timestamp,
+                   st->index_entries[st->nb_index_entries - 1].timestamp);
         return AVERROR_INVALIDDATA;
     }
 
     /* find the position */
-    pos       = st->internal->index_entries[index].pos;
-    timestamp = st->internal->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
+    pos       = st->index_entries[index].pos;
+    timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
 
     av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
-            timestamp, index, st->internal->index_entries[index].timestamp);
+            timestamp, index, st->index_entries[index].timestamp);
 
     if (CONFIG_DV_DEMUXER && avi->dv_demux) {
         /* One and only one real stream for DV in AVI, and it has video  */
@@ -1888,7 +1888,7 @@  static int avi_read_seek(AVFormatContext *s, int stream_index,
             continue;
         }
 
-        if (st2->internal->nb_index_entries <= 0)
+        if (st2->nb_index_entries <= 0)
             continue;
 
 //        av_assert1(st2->codecpar->block_align);
@@ -1902,14 +1902,14 @@  static int avi_read_seek(AVFormatContext *s, int stream_index,
                                           (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
         if (index < 0)
             index = 0;
-        ast2->seek_pos = st2->internal->index_entries[index].pos;
+        ast2->seek_pos = st2->index_entries[index].pos;
         pos_min = FFMIN(pos_min,ast2->seek_pos);
     }
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st2 = s->streams[i];
         AVIStream *ast2 = st2->priv_data;
 
-        if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0)
+        if (ast2->sub_ctx || st2->nb_index_entries <= 0)
             continue;
 
         index = av_index_search_timestamp(
@@ -1918,9 +1918,9 @@  static int avi_read_seek(AVFormatContext *s, int stream_index,
                 flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
         if (index < 0)
             index = 0;
-        while (!avi->non_interleaved && index>0 && st2->internal->index_entries[index-1].pos >= pos_min)
+        while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)
             index--;
-        ast2->frame_offset = st2->internal->index_entries[index].timestamp;
+        ast2->frame_offset = st2->index_entries[index].timestamp;
     }
 
     /* do the seek */
diff --git a/libavformat/bink.c b/libavformat/bink.c
index 99bbd27ef3..08125ba8f1 100644
--- a/libavformat/bink.c
+++ b/libavformat/bink.c
@@ -225,8 +225,8 @@  static int read_header(AVFormatContext *s)
             return ret;
     }
 
-    if (vst->internal->index_entries)
-        avio_seek(pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET);
+    if (vst->index_entries)
+        avio_seek(pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET);
     else
         avio_skip(pb, 4);
 
@@ -256,8 +256,8 @@  static int read_packet(AVFormatContext *s, AVPacket *pkt)
             return AVERROR(EIO);
         }
 
-        bink->remain_packet_size = st->internal->index_entries[index_entry].size;
-        bink->flags = st->internal->index_entries[index_entry].flags;
+        bink->remain_packet_size = st->index_entries[index_entry].size;
+        bink->flags = st->index_entries[index_entry].flags;
         bink->current_track = 0;
     }
 
@@ -313,7 +313,7 @@  static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
         return -1;
 
     /* seek to the first frame */
-    ret = avio_seek(s->pb, vst->internal->index_entries[0].pos + bink->smush_size, SEEK_SET);
+    ret = avio_seek(s->pb, vst->index_entries[0].pos + bink->smush_size, SEEK_SET);
     if (ret < 0)
         return ret;
 
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index d56187f71f..c1bf7eed6a 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -337,7 +337,7 @@  found_data:
     if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
         if (caf->data_size > 0)
             st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
-    } else if (st->internal->nb_index_entries && st->duration > 0) {
+    } else if (st->nb_index_entries && st->duration > 0) {
         if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) {
             av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n",
                    st->codecpar->sample_rate, caf->data_size / st->duration);
@@ -390,13 +390,13 @@  static int read_packet(AVFormatContext *s, AVPacket *pkt)
         pkt_size   = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size;
         pkt_size   = FFMIN(pkt_size, left);
         pkt_frames = pkt_size / caf->bytes_per_packet;
-    } else if (st->internal->nb_index_entries) {
-        if (caf->packet_cnt < st->internal->nb_index_entries - 1) {
-            pkt_size   = st->internal->index_entries[caf->packet_cnt + 1].pos       - st->internal->index_entries[caf->packet_cnt].pos;
-            pkt_frames = st->internal->index_entries[caf->packet_cnt + 1].timestamp - st->internal->index_entries[caf->packet_cnt].timestamp;
-        } else if (caf->packet_cnt == st->internal->nb_index_entries - 1) {
-            pkt_size   = caf->num_bytes - st->internal->index_entries[caf->packet_cnt].pos;
-            pkt_frames = st->duration   - st->internal->index_entries[caf->packet_cnt].timestamp;
+    } else if (st->nb_index_entries) {
+        if (caf->packet_cnt < st->nb_index_entries - 1) {
+            pkt_size   = st->index_entries[caf->packet_cnt + 1].pos       - st->index_entries[caf->packet_cnt].pos;
+            pkt_frames = st->index_entries[caf->packet_cnt + 1].timestamp - st->index_entries[caf->packet_cnt].timestamp;
+        } else if (caf->packet_cnt == st->nb_index_entries - 1) {
+            pkt_size   = caf->num_bytes - st->index_entries[caf->packet_cnt].pos;
+            pkt_frames = st->duration   - st->index_entries[caf->packet_cnt].timestamp;
         } else {
             return AVERROR(EIO);
         }
@@ -435,10 +435,10 @@  static int read_seek(AVFormatContext *s, int stream_index,
             pos = FFMIN(pos, caf->data_size);
         packet_cnt = pos / caf->bytes_per_packet;
         frame_cnt  = caf->frames_per_packet * packet_cnt;
-    } else if (st->internal->nb_index_entries) {
+    } else if (st->nb_index_entries) {
         packet_cnt = av_index_search_timestamp(st, timestamp, flags);
-        frame_cnt  = st->internal->index_entries[packet_cnt].timestamp;
-        pos        = st->internal->index_entries[packet_cnt].pos;
+        frame_cnt  = st->index_entries[packet_cnt].timestamp;
+        pos        = st->index_entries[packet_cnt].pos;
     } else {
         return -1;
     }
diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c
index e5c6468c39..88f5e56902 100644
--- a/libavformat/cinedec.c
+++ b/libavformat/cinedec.c
@@ -288,10 +288,10 @@  static int cine_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     AVIOContext *pb = avctx->pb;
     int n, size, ret;
 
-    if (cine->pts >= st->internal->nb_index_entries)
+    if (cine->pts >= st->nb_index_entries)
         return AVERROR_EOF;
 
-    avio_seek(pb, st->internal->index_entries[cine->pts].pos, SEEK_SET);
+    avio_seek(pb, st->index_entries[cine->pts].pos, SEEK_SET);
     n = avio_rl32(pb);
     if (n < 8)
         return AVERROR_INVALIDDATA;
diff --git a/libavformat/dhav.c b/libavformat/dhav.c
index 526331ae4c..d5d25801ca 100644
--- a/libavformat/dhav.c
+++ b/libavformat/dhav.c
@@ -434,10 +434,10 @@  static int dhav_read_seek(AVFormatContext *s, int stream_index,
 
     if (index < 0)
         return -1;
-    if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
+    if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
         return -1;
 
-    pts = st->internal->index_entries[index].timestamp;
+    pts = st->index_entries[index].timestamp;
 
     for (int n = 0; n < s->nb_streams; n++) {
         AVStream *st = s->streams[n];
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index f7b21986dc..1463e1caa8 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -40,8 +40,8 @@  static void reset_index_position(int64_t metadata_head_size, AVStream *st)
 {
     /* the real seek index offset should be the size of metadata blocks with the offset in the frame blocks */
     int i;
-    for(i=0; i<st->internal->nb_index_entries; i++) {
-        st->internal->index_entries[i].pos += metadata_head_size;
+    for(i=0; i<st->nb_index_entries; i++) {
+        st->index_entries[i].pos += metadata_head_size;
     }
 }
 
@@ -318,10 +318,10 @@  static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, in
     }
 
     index = av_index_search_timestamp(s->streams[0], timestamp, flags);
-    if(index<0 || index >= s->streams[0]->internal->nb_index_entries)
+    if(index<0 || index >= s->streams[0]->nb_index_entries)
         return -1;
 
-    e = s->streams[0]->internal->index_entries[index];
+    e = s->streams[0]->index_entries[index];
     pos = avio_seek(s->pb, e.pos, SEEK_SET);
     if (pos >= 0) {
         return 0;
diff --git a/libavformat/flic.c b/libavformat/flic.c
index 9a7b8081ed..4552bff69c 100644
--- a/libavformat/flic.c
+++ b/libavformat/flic.c
@@ -268,7 +268,7 @@  static int flic_read_seek(AVFormatContext *s, int stream_index,
     int64_t pos, ts;
     int index;
 
-    if (!st->internal->index_entries || stream_index != flic->video_stream_index)
+    if (!st->index_entries || stream_index != flic->video_stream_index)
         return -1;
 
     index = av_index_search_timestamp(st, pts, flags);
@@ -278,8 +278,8 @@  static int flic_read_seek(AVFormatContext *s, int stream_index,
     if (index < 0)
         return -1;
 
-    pos = st->internal->index_entries[index].pos;
-    ts  = st->internal->index_entries[index].timestamp;
+    pos = st->index_entries[index].pos;
+    ts  = st->index_entries[index].timestamp;
     flic->frame_number = ts;
     avio_seek(s->pb, pos, SEEK_SET);
     return 0;
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index e4b40a195c..576d58295c 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -142,7 +142,7 @@  static void add_keyframes_index(AVFormatContext *s)
     av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
     stream = s->streams[flv->last_keyframe_stream_index];
 
-    if (stream->internal->nb_index_entries == 0) {
+    if (stream->nb_index_entries == 0) {
         for (i = 0; i < flv->keyframe_count; i++) {
             av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
                    flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
@@ -844,10 +844,10 @@  static void clear_index_entries(AVFormatContext *s, int64_t pos)
         AVStream *st = s->streams[i];
         /* Remove all index entries that point to >= pos */
         out = 0;
-        for (j = 0; j < st->internal->nb_index_entries; j++)
-            if (st->internal->index_entries[j].pos < pos)
-                st->internal->index_entries[out++] = st->internal->index_entries[j];
-        st->internal->nb_index_entries = out;
+        for (j = 0; j < st->nb_index_entries; j++)
+            if (st->index_entries[j].pos < pos)
+                st->index_entries[out++] = st->index_entries[j];
+        st->nb_index_entries = out;
     }
 }
 
diff --git a/libavformat/gxf.c b/libavformat/gxf.c
index b787d4f521..bbad47c240 100644
--- a/libavformat/gxf.c
+++ b/libavformat/gxf.c
@@ -575,9 +575,9 @@  static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int
                                     AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
     if (idx < 0)
         return -1;
-    pos = st->internal->index_entries[idx].pos;
-    if (idx < st->internal->nb_index_entries - 2)
-        maxlen = st->internal->index_entries[idx + 2].pos - pos;
+    pos = st->index_entries[idx].pos;
+    if (idx < st->nb_index_entries - 2)
+        maxlen = st->index_entries[idx + 2].pos - pos;
     maxlen = FFMAX(maxlen, 200 * 1024);
     res = avio_seek(s->pb, pos, SEEK_SET);
     if (res < 0)
diff --git a/libavformat/ifv.c b/libavformat/ifv.c
index bca8f85d09..4e904fa828 100644
--- a/libavformat/ifv.c
+++ b/libavformat/ifv.c
@@ -195,15 +195,15 @@  static int ifv_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (ifv->next_video_index < ifv->total_vframes) {
         st = s->streams[ifv->video_stream_index];
-        if (ifv->next_video_index < st->internal->nb_index_entries)
-            e_next = ev = &st->internal->index_entries[ifv->next_video_index];
+        if (ifv->next_video_index < st->nb_index_entries)
+            e_next = ev = &st->index_entries[ifv->next_video_index];
     }
 
     if (ifv->is_audio_present &&
         ifv->next_audio_index < ifv->total_aframes) {
         st = s->streams[ifv->audio_stream_index];
-        if (ifv->next_audio_index < st->internal->nb_index_entries) {
-            ea = &st->internal->index_entries[ifv->next_audio_index];
+        if (ifv->next_audio_index < st->nb_index_entries) {
+            ea = &st->index_entries[ifv->next_audio_index];
             if (!ev || ea->timestamp < ev->timestamp)
                 e_next = ea;
         }
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index be7149bb2f..65e3c9b1a3 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -590,7 +590,7 @@  static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
         int index = av_index_search_timestamp(st, timestamp, flags);
         if(index < 0)
             return -1;
-        s1->img_number = st->internal->index_entries[index].pos;
+        s1->img_number = st->index_entries[index].pos;
         return 0;
     }
 
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 3c6b2921c1..8ed4ee1c9a 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -236,11 +236,6 @@  struct AVStreamInternal {
 
     } *info;
 
-    AVIndexEntry *index_entries; /**< Only used if the format does not
-                                    support seeking natively. */
-    int nb_index_entries;
-    unsigned int index_entries_allocated_size;
-
     int64_t interleaver_chunk_size;
     int64_t interleaver_chunk_duration;
 
diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c
index 47d18e2beb..551f8069e6 100644
--- a/libavformat/jvdec.c
+++ b/libavformat/jvdec.c
@@ -92,7 +92,7 @@  static int read_header(AVFormatContext *s)
     vst->codecpar->height      = avio_rl16(pb);
     vst->duration           =
     vst->nb_frames          =
-    ast->internal->nb_index_entries   = avio_rl16(pb);
+    ast->nb_index_entries   = avio_rl16(pb);
     avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000);
 
     avio_skip(pb, 4);
@@ -107,19 +107,19 @@  static int read_header(AVFormatContext *s)
 
     avio_skip(pb, 10);
 
-    ast->internal->index_entries = av_malloc(ast->internal->nb_index_entries *
-                                   sizeof(*ast->internal->index_entries));
-    if (!ast->internal->index_entries)
+    ast->index_entries = av_malloc(ast->nb_index_entries *
+                                   sizeof(*ast->index_entries));
+    if (!ast->index_entries)
         return AVERROR(ENOMEM);
 
-    jv->frames = av_malloc(ast->internal->nb_index_entries * sizeof(JVFrame));
+    jv->frames = av_malloc(ast->nb_index_entries * sizeof(JVFrame));
     if (!jv->frames) {
-        av_freep(&ast->internal->index_entries);
+        av_freep(&ast->index_entries);
         return AVERROR(ENOMEM);
     }
-    offset = 0x68 + ast->internal->nb_index_entries * 16;
-    for (i = 0; i < ast->internal->nb_index_entries; i++) {
-        AVIndexEntry *e   = ast->internal->index_entries + i;
+    offset = 0x68 + ast->nb_index_entries * 16;
+    for (i = 0; i < ast->nb_index_entries; i++) {
+        AVIndexEntry *e   = ast->index_entries + i;
         JVFrame      *jvf = jv->frames + i;
 
         /* total frame size including audio, video, palette data and padding */
@@ -139,7 +139,7 @@  static int read_header(AVFormatContext *s)
             if (s->error_recognition & AV_EF_EXPLODE) {
                 read_close(s);
                 av_freep(&jv->frames);
-                av_freep(&ast->internal->index_entries);
+                av_freep(&ast->index_entries);
                 return AVERROR_INVALIDDATA;
             }
             jvf->audio_size   =
@@ -170,8 +170,8 @@  static int read_packet(AVFormatContext *s, AVPacket *pkt)
     AVStream *ast = s->streams[0];
     int ret;
 
-    while (!avio_feof(s->pb) && jv->pts < ast->internal->nb_index_entries) {
-        const AVIndexEntry *e   = ast->internal->index_entries + jv->pts;
+    while (!avio_feof(s->pb) && jv->pts < ast->nb_index_entries) {
+        const AVIndexEntry *e   = ast->index_entries + jv->pts;
         const JVFrame      *jvf = jv->frames + jv->pts;
 
         switch (jv->state) {
@@ -244,9 +244,9 @@  static int read_seek(AVFormatContext *s, int stream_index,
         return 0;
     }
 
-    if (i < 0 || i >= ast->internal->nb_index_entries)
+    if (i < 0 || i >= ast->nb_index_entries)
         return 0;
-    if (avio_seek(s->pb, ast->internal->index_entries[i].pos, SEEK_SET) < 0)
+    if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0)
         return -1;
 
     jv->state = JV_AUDIO;
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 9acfdf5b32..65756ae06d 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3845,13 +3845,13 @@  static int matroska_read_seek(AVFormatContext *s, int stream_index,
         matroska_parse_cues(matroska);
     }
 
-    if (!st->internal->nb_index_entries)
+    if (!st->nb_index_entries)
         goto err;
-    timestamp = FFMAX(timestamp, st->internal->index_entries[0].timestamp);
+    timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
 
-    if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) {
-        matroska_reset_status(matroska, 0, st->internal->index_entries[st->internal->nb_index_entries - 1].pos);
-        while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->internal->nb_index_entries - 1) {
+    if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
+        matroska_reset_status(matroska, 0, st->index_entries[st->nb_index_entries - 1].pos);
+        while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0 || index == st->nb_index_entries - 1) {
             matroska_clear_queue(matroska);
             if (matroska_parse_cluster(matroska) < 0)
                 break;
@@ -3859,7 +3859,7 @@  static int matroska_read_seek(AVFormatContext *s, int stream_index,
     }
 
     matroska_clear_queue(matroska);
-    if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->internal->nb_index_entries - 1))
+    if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1))
         goto err;
 
     tracks = matroska->tracks.elem;
@@ -3871,17 +3871,17 @@  static int matroska_read_seek(AVFormatContext *s, int stream_index,
     }
 
     /* We seek to a level 1 element, so set the appropriate status. */
-    matroska_reset_status(matroska, 0, st->internal->index_entries[index].pos);
+    matroska_reset_status(matroska, 0, st->index_entries[index].pos);
     if (flags & AVSEEK_FLAG_ANY) {
         st->internal->skip_to_keyframe = 0;
         matroska->skip_to_timecode = timestamp;
     } else {
         st->internal->skip_to_keyframe = 1;
-        matroska->skip_to_timecode = st->internal->index_entries[index].timestamp;
+        matroska->skip_to_timecode = st->index_entries[index].timestamp;
     }
     matroska->skip_to_keyframe = 1;
     matroska->done             = 0;
-    ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp);
+    ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
     return 0;
 err:
     // slightly hackish but allows proper fallback to
@@ -3927,8 +3927,8 @@  static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start)
     MatroskaDemuxContext *matroska = s->priv_data;
     CueDesc cue_desc;
     int i;
-    int nb_index_entries = s->streams[0]->internal->nb_index_entries;
-    AVIndexEntry *index_entries = s->streams[0]->internal->index_entries;
+    int nb_index_entries = s->streams[0]->nb_index_entries;
+    AVIndexEntry *index_entries = s->streams[0]->index_entries;
     if (ts >= matroska->duration * matroska->time_scale) return (CueDesc) {-1, -1, -1, -1};
     for (i = 1; i < nb_index_entries; i++) {
         if (index_entries[i - 1].timestamp * matroska->time_scale <= ts &&
@@ -3958,11 +3958,11 @@  static int webm_clusters_start_with_keyframe(AVFormatContext *s)
     uint32_t id = matroska->current_id;
     int64_t cluster_pos, before_pos;
     int index, rv = 1;
-    if (s->streams[0]->internal->nb_index_entries <= 0) return 0;
+    if (s->streams[0]->nb_index_entries <= 0) return 0;
     // seek to the first cluster using cues.
     index = av_index_search_timestamp(s->streams[0], 0, 0);
     if (index < 0)  return 0;
-    cluster_pos = s->streams[0]->internal->index_entries[index].pos;
+    cluster_pos = s->streams[0]->index_entries[index].pos;
     before_pos = avio_tell(s->pb);
     while (1) {
         uint64_t cluster_id, cluster_length;
@@ -4086,9 +4086,9 @@  static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t
     double bandwidth = 0.0;
     int i;
 
-    for (i = 0; i < st->internal->nb_index_entries; i++) {
+    for (i = 0; i < st->nb_index_entries; i++) {
         int64_t prebuffer_ns = 1000000000;
-        int64_t time_ns = st->internal->index_entries[i].timestamp * matroska->time_scale;
+        int64_t time_ns = st->index_entries[i].timestamp * matroska->time_scale;
         double nano_seconds_per_second = 1000000000.0;
         int64_t prebuffered_ns = time_ns + prebuffer_ns;
         double prebuffer_bytes = 0.0;
@@ -4226,14 +4226,14 @@  static int webm_dash_manifest_cues(AVFormatContext *s, int64_t init_range)
 
     // store cue point timestamps as a comma separated list for checking subsegment alignment in
     // the muxer. assumes that each timestamp cannot be more than 20 characters long.
-    buf = av_malloc_array(s->streams[0]->internal->nb_index_entries, 20);
+    buf = av_malloc_array(s->streams[0]->nb_index_entries, 20);
     if (!buf) return -1;
     strcpy(buf, "");
-    for (i = 0; i < s->streams[0]->internal->nb_index_entries; i++) {
+    for (i = 0; i < s->streams[0]->nb_index_entries; i++) {
         int ret = snprintf(buf + end, 20,
-                           "%" PRId64"%s", s->streams[0]->internal->index_entries[i].timestamp,
-                           i != s->streams[0]->internal->nb_index_entries - 1 ? "," : "");
-        if (ret <= 0 || (ret == 20 && i ==  s->streams[0]->internal->nb_index_entries - 1)) {
+                           "%" PRId64"%s", s->streams[0]->index_entries[i].timestamp,
+                           i != s->streams[0]->nb_index_entries - 1 ? "," : "");
+        if (ret <= 0 || (ret == 20 && i ==  s->streams[0]->nb_index_entries - 1)) {
             av_log(s, AV_LOG_ERROR, "timestamp too long.\n");
             av_free(buf);
             return AVERROR_INVALIDDATA;
diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c
index 1ddef3461e..f08aabf4e0 100644
--- a/libavformat/mlvdec.c
+++ b/libavformat/mlvdec.c
@@ -191,12 +191,12 @@  static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f
             }
         } else if (vst && type == MKTAG('V', 'I', 'D', 'F') && size >= 4) {
             uint64_t pts = avio_rl32(pb);
-            ff_add_index_entry(&vst->internal->index_entries, &vst->internal->nb_index_entries, &vst->internal->index_entries_allocated_size,
+            ff_add_index_entry(&vst->index_entries, &vst->nb_index_entries, &vst->index_entries_allocated_size,
                                avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
             size -= 4;
         } else if (ast && type == MKTAG('A', 'U', 'D', 'F') && size >= 4) {
             uint64_t pts = avio_rl32(pb);
-            ff_add_index_entry(&ast->internal->index_entries, &ast->internal->nb_index_entries, &ast->internal->index_entries_allocated_size,
+            ff_add_index_entry(&ast->index_entries, &ast->nb_index_entries, &ast->index_entries_allocated_size,
                                avio_tell(pb) - 20, pts, file, 0, AVINDEX_KEYFRAME);
             size -= 4;
         } else if (vst && type == MKTAG('W','B','A','L') && size >= 28) {
@@ -374,22 +374,22 @@  static int read_header(AVFormatContext *avctx)
     }
 
     if (vst)
-        vst->duration = vst->internal->nb_index_entries;
+        vst->duration = vst->nb_index_entries;
     if (ast)
-        ast->duration = ast->internal->nb_index_entries;
+        ast->duration = ast->nb_index_entries;
 
-    if ((vst && !vst->internal->nb_index_entries) || (ast && !ast->internal->nb_index_entries)) {
+    if ((vst && !vst->nb_index_entries) || (ast && !ast->nb_index_entries)) {
         av_log(avctx, AV_LOG_ERROR, "no index entries found\n");
         read_close(avctx);
         return AVERROR_INVALIDDATA;
     }
 
     if (vst && ast)
-        avio_seek(pb, FFMIN(vst->internal->index_entries[0].pos, ast->internal->index_entries[0].pos), SEEK_SET);
+        avio_seek(pb, FFMIN(vst->index_entries[0].pos, ast->index_entries[0].pos), SEEK_SET);
     else if (vst)
-        avio_seek(pb, vst->internal->index_entries[0].pos, SEEK_SET);
+        avio_seek(pb, vst->index_entries[0].pos, SEEK_SET);
     else if (ast)
-        avio_seek(pb, ast->internal->index_entries[0].pos, SEEK_SET);
+        avio_seek(pb, ast->index_entries[0].pos, SEEK_SET);
 
     return 0;
 }
@@ -415,12 +415,12 @@  static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
         return AVERROR(EIO);
     }
 
-    pb = mlv->pb[st->internal->index_entries[index].size];
+    pb = mlv->pb[st->index_entries[index].size];
     if (!pb) {
         ret = FFERROR_REDO;
         goto next_packet;
     }
-    avio_seek(pb, st->internal->index_entries[index].pos, SEEK_SET);
+    avio_seek(pb, st->index_entries[index].pos, SEEK_SET);
 
     avio_skip(pb, 4); // blockType
     size = avio_rl32(pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index aef5517c2c..9f717a94eb 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3210,8 +3210,8 @@  static int find_prev_closest_index(AVStream *st,
                                    int64_t* ctts_sample)
 {
     MOVStreamContext *msc = st->priv_data;
-    AVIndexEntry *e_keep = st->internal->index_entries;
-    int nb_keep = st->internal->nb_index_entries;
+    AVIndexEntry *e_keep = st->index_entries;
+    int nb_keep = st->nb_index_entries;
     int64_t i = 0;
     int64_t index_ctts_count;
 
@@ -3224,8 +3224,8 @@  static int find_prev_closest_index(AVStream *st,
         timestamp_pts -= msc->dts_shift;
     }
 
-    st->internal->index_entries = e_old;
-    st->internal->nb_index_entries = nb_old;
+    st->index_entries = e_old;
+    st->nb_index_entries = nb_old;
     *index = av_index_search_timestamp(st, timestamp_pts, flag | AVSEEK_FLAG_BACKWARD);
 
     // Keep going backwards in the index entries until the timestamp is the same.
@@ -3278,14 +3278,14 @@  static int find_prev_closest_index(AVStream *st,
     }
 
     /* restore AVStream state*/
-    st->internal->index_entries = e_keep;
-    st->internal->nb_index_entries = nb_keep;
+    st->index_entries = e_keep;
+    st->nb_index_entries = nb_keep;
     return *index >= 0 ? 0 : -1;
 }
 
 /**
- * Add index entry with the given values, to the end of st->internal->index_entries.
- * Returns the new size st->internal->index_entries if successful, else returns -1.
+ * Add index entry with the given values, to the end of st->index_entries.
+ * Returns the new size st->index_entries if successful, else returns -1.
  *
  * This function is similar to ff_add_index_entry in libavformat/utils.c
  * except that here we are always unconditionally adding an index entry to
@@ -3299,27 +3299,27 @@  static int64_t add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
 {
     AVIndexEntry *entries, *ie;
     int64_t index = -1;
-    const size_t min_size_needed = (st->internal->nb_index_entries + 1) * sizeof(AVIndexEntry);
+    const size_t min_size_needed = (st->nb_index_entries + 1) * sizeof(AVIndexEntry);
 
     // Double the allocation each time, to lower memory fragmentation.
     // Another difference from ff_add_index_entry function.
     const size_t requested_size =
-        min_size_needed > st->internal->index_entries_allocated_size ?
-        FFMAX(min_size_needed, 2 * st->internal->index_entries_allocated_size) :
+        min_size_needed > st->index_entries_allocated_size ?
+        FFMAX(min_size_needed, 2 * st->index_entries_allocated_size) :
         min_size_needed;
 
-    if (st->internal->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry))
+    if (st->nb_index_entries + 1U >= UINT_MAX / sizeof(AVIndexEntry))
         return -1;
 
-    entries = av_fast_realloc(st->internal->index_entries,
-                              &st->internal->index_entries_allocated_size,
+    entries = av_fast_realloc(st->index_entries,
+                              &st->index_entries_allocated_size,
                               requested_size);
     if (!entries)
         return -1;
 
-    st->internal->index_entries= entries;
+    st->index_entries= entries;
 
-    index= st->internal->nb_index_entries++;
+    index= st->nb_index_entries++;
     ie= &entries[index];
 
     ie->pos = pos;
@@ -3338,10 +3338,10 @@  static void fix_index_entry_timestamps(AVStream* st, int end_index, int64_t end_
                                        int64_t* frame_duration_buffer,
                                        int frame_duration_buffer_size) {
     int i = 0;
-    av_assert0(end_index >= 0 && end_index <= st->internal->nb_index_entries);
+    av_assert0(end_index >= 0 && end_index <= st->nb_index_entries);
     for (i = 0; i < frame_duration_buffer_size; i++) {
         end_ts -= frame_duration_buffer[frame_duration_buffer_size - 1 - i];
-        st->internal->index_entries[end_index - 1 - i].timestamp = end_ts;
+        st->index_entries[end_index - 1 - i].timestamp = end_ts;
     }
 }
 
@@ -3393,14 +3393,14 @@  static void mov_estimate_video_delay(MOVContext *c, AVStream* st)
     if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
         st->codecpar->codec_id == AV_CODEC_ID_H264) {
         st->codecpar->video_delay = 0;
-        for (ind = 0; ind < st->internal->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
+        for (ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
             // Point j to the last elem of the buffer and insert the current pts there.
             j = buf_start;
             buf_start = (buf_start + 1);
             if (buf_start == MAX_REORDER_DELAY + 1)
                 buf_start = 0;
 
-            pts_buf[j] = st->internal->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
+            pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
 
             // The timestamps that are already in the sorted buffer, and are greater than the
             // current pts, are exactly the timestamps that need to be buffered to output PTS
@@ -3480,7 +3480,7 @@  static void mov_current_sample_set(MOVStreamContext *sc, int current_sample)
 }
 
 /**
- * Fix st->internal->index_entries, so that it contains only the entries (and the entries
+ * Fix st->index_entries, so that it contains only the entries (and the entries
  * which are needed to decode them) that fall in the edit list time ranges.
  * Also fixes the timestamps of the index entries to match the timeline
  * specified the edit lists.
@@ -3488,8 +3488,8 @@  static void mov_current_sample_set(MOVStreamContext *sc, int current_sample)
 static void mov_fix_index(MOVContext *mov, AVStream *st)
 {
     MOVStreamContext *msc = st->priv_data;
-    AVIndexEntry *e_old = st->internal->index_entries;
-    int nb_old = st->internal->nb_index_entries;
+    AVIndexEntry *e_old = st->index_entries;
+    int nb_old = st->nb_index_entries;
     const AVIndexEntry *e_old_end = e_old + nb_old;
     const AVIndexEntry *current = NULL;
     MOVStts *ctts_data_old = msc->ctts_data;
@@ -3534,9 +3534,9 @@  static void mov_fix_index(MOVContext *mov, AVStream *st)
     current_index_range = msc->index_ranges - 1;
 
     // Clean AVStream from traces of old index
-    st->internal->index_entries = NULL;
-    st->internal->index_entries_allocated_size = 0;
-    st->internal->nb_index_entries = 0;
+    st->index_entries = NULL;
+    st->index_entries_allocated_size = 0;
+    st->nb_index_entries = 0;
 
     // Clean ctts fields of MOVStreamContext
     msc->ctts_data = NULL;
@@ -3665,7 +3665,7 @@  static void mov_fix_index(MOVContext *mov, AVStream *st)
                         // Make timestamps strictly monotonically increasing for audio, by rewriting timestamps for
                         // discarded packets.
                         if (frame_duration_buffer) {
-                            fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter,
+                            fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
                                                        frame_duration_buffer, num_discarded_begin);
                             av_freep(&frame_duration_buffer);
                         }
@@ -3704,7 +3704,7 @@  static void mov_fix_index(MOVContext *mov, AVStream *st)
                     // Make timestamps strictly monotonically increasing by rewriting timestamps for
                     // discarded packets.
                     if (frame_duration_buffer) {
-                        fix_index_entry_timestamps(st, st->internal->nb_index_entries, edit_list_dts_counter,
+                        fix_index_entry_timestamps(st, st->nb_index_entries, edit_list_dts_counter,
                                                    frame_duration_buffer, num_discarded_begin);
                         av_freep(&frame_duration_buffer);
                     }
@@ -3765,8 +3765,8 @@  static void mov_fix_index(MOVContext *mov, AVStream *st)
     if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
         if (msc->min_corrected_pts > 0) {
             av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts);
-            for (i = 0; i < st->internal->nb_index_entries; ++i) {
-                st->internal->index_entries[i].timestamp -= msc->min_corrected_pts;
+            for (i = 0; i < st->nb_index_entries; ++i) {
+                st->index_entries[i].timestamp -= msc->min_corrected_pts;
             }
         }
     }
@@ -3859,17 +3859,17 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
         current_dts -= sc->dts_shift;
         last_dts     = current_dts;
 
-        if (!sc->sample_count || st->internal->nb_index_entries)
+        if (!sc->sample_count || st->nb_index_entries)
             return;
-        if (sc->sample_count >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries)
+        if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
             return;
-        if (av_reallocp_array(&st->internal->index_entries,
-                              st->internal->nb_index_entries + sc->sample_count,
-                              sizeof(*st->internal->index_entries)) < 0) {
-            st->internal->nb_index_entries = 0;
+        if (av_reallocp_array(&st->index_entries,
+                              st->nb_index_entries + sc->sample_count,
+                              sizeof(*st->index_entries)) < 0) {
+            st->nb_index_entries = 0;
             return;
         }
-        st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + sc->sample_count) * sizeof(*st->internal->index_entries);
+        st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries);
 
         if (ctts_data_old) {
             // Expand ctts entries such that we have a 1-1 mapping with samples
@@ -3952,7 +3952,7 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
                         av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", sample_size);
                         return;
                     }
-                    e = &st->internal->index_entries[st->internal->nb_index_entries++];
+                    e = &st->index_entries[st->nb_index_entries++];
                     e->pos = current_offset;
                     e->timestamp = current_dts;
                     e->size = sample_size;
@@ -3961,7 +3961,7 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
                     av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", "
                             "size %u, distance %u, keyframe %d\n", st->index, current_sample,
                             current_offset, current_dts, sample_size, distance, keyframe);
-                    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries < 100)
+                    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100)
                         ff_rfps_add_frame(mov->fc, st, current_dts);
                 }
 
@@ -4033,15 +4033,15 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
         }
 
         av_log(mov->fc, AV_LOG_TRACE, "chunk count %u\n", total);
-        if (total >= UINT_MAX / sizeof(*st->internal->index_entries) - st->internal->nb_index_entries)
+        if (total >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
             return;
-        if (av_reallocp_array(&st->internal->index_entries,
-                              st->internal->nb_index_entries + total,
-                              sizeof(*st->internal->index_entries)) < 0) {
-            st->internal->nb_index_entries = 0;
+        if (av_reallocp_array(&st->index_entries,
+                              st->nb_index_entries + total,
+                              sizeof(*st->index_entries)) < 0) {
+            st->nb_index_entries = 0;
             return;
         }
-        st->internal->index_entries_allocated_size = (st->internal->nb_index_entries + total) * sizeof(*st->internal->index_entries);
+        st->index_entries_allocated_size = (st->nb_index_entries + total) * sizeof(*st->index_entries);
 
         // populate index
         for (i = 0; i < sc->chunk_count; i++) {
@@ -4076,7 +4076,7 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
                     }
                 }
 
-                if (st->internal->nb_index_entries >= total) {
+                if (st->nb_index_entries >= total) {
                     av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %u\n", total);
                     return;
                 }
@@ -4084,7 +4084,7 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
                     av_log(mov->fc, AV_LOG_ERROR, "Sample size %u is too large\n", size);
                     return;
                 }
-                e = &st->internal->index_entries[st->internal->nb_index_entries++];
+                e = &st->index_entries[st->nb_index_entries++];
                 e->pos = current_offset;
                 e->timestamp = current_dts;
                 e->size = size;
@@ -4107,8 +4107,8 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
     }
 
     // Update start time of the stream.
-    if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->nb_index_entries > 0) {
-        st->start_time = st->internal->index_entries[0].timestamp + sc->dts_shift;
+    if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) {
+        st->start_time = st->index_entries[0].timestamp + sc->dts_shift;
         if (sc->ctts_data) {
             st->start_time += sc->ctts_data[0].duration;
         }
@@ -4806,7 +4806,7 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     // A valid index_entry means the trun for the fragment was read
     // and it's samples are in index_entries at the given position.
     // New index entries will be inserted before the index_entry found.
-    index_entry_pos = st->internal->nb_index_entries;
+    index_entry_pos = st->nb_index_entries;
     for (i = c->frag_index.current + 1; i < c->frag_index.nb_items; i++) {
         frag_stream_info = get_frag_stream_info(&c->frag_index, i, frag->track_id);
         if (frag_stream_info && frag_stream_info->index_entry >= 0) {
@@ -4815,7 +4815,7 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
             break;
         }
     }
-    av_assert0(index_entry_pos <= st->internal->nb_index_entries);
+    av_assert0(index_entry_pos <= st->nb_index_entries);
 
     avio_r8(pb); /* version */
     flags = avio_rb24(pb);
@@ -4866,22 +4866,22 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     av_log(c->fc, AV_LOG_TRACE, "first sample flags 0x%x\n", first_sample_flags);
 
     // realloc space for new index entries
-    if((uint64_t)st->internal->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) {
-        entries = UINT_MAX / sizeof(AVIndexEntry) - st->internal->nb_index_entries;
+    if((uint64_t)st->nb_index_entries + entries >= UINT_MAX / sizeof(AVIndexEntry)) {
+        entries = UINT_MAX / sizeof(AVIndexEntry) - st->nb_index_entries;
         av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
     }
     if (entries == 0)
         return 0;
 
-    requested_size = (st->internal->nb_index_entries + entries) * sizeof(AVIndexEntry);
-    new_entries = av_fast_realloc(st->internal->index_entries,
-                                  &st->internal->index_entries_allocated_size,
+    requested_size = (st->nb_index_entries + entries) * sizeof(AVIndexEntry);
+    new_entries = av_fast_realloc(st->index_entries,
+                                  &st->index_entries_allocated_size,
                                   requested_size);
     if (!new_entries)
         return AVERROR(ENOMEM);
-    st->internal->index_entries= new_entries;
+    st->index_entries= new_entries;
 
-    requested_size = (st->internal->nb_index_entries + entries) * sizeof(*sc->ctts_data);
+    requested_size = (st->nb_index_entries + entries) * sizeof(*sc->ctts_data);
     old_ctts_allocated_size = sc->ctts_allocated_size;
     ctts_data = av_fast_realloc(sc->ctts_data, &sc->ctts_allocated_size,
                                 requested_size);
@@ -4895,12 +4895,12 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     memset((uint8_t*)(sc->ctts_data) + old_ctts_allocated_size, 0,
            sc->ctts_allocated_size - old_ctts_allocated_size);
 
-    if (index_entry_pos < st->internal->nb_index_entries) {
+    if (index_entry_pos < st->nb_index_entries) {
         // Make hole in index_entries and ctts_data for new samples
-        memmove(st->internal->index_entries + index_entry_pos + entries,
-                st->internal->index_entries + index_entry_pos,
-                sizeof(*st->internal->index_entries) *
-                (st->internal->nb_index_entries - index_entry_pos));
+        memmove(st->index_entries + index_entry_pos + entries,
+                st->index_entries + index_entry_pos,
+                sizeof(*st->index_entries) *
+                (st->nb_index_entries - index_entry_pos));
         memmove(sc->ctts_data + index_entry_pos + entries,
                 sc->ctts_data + index_entry_pos,
                 sizeof(*sc->ctts_data) * (sc->ctts_count - index_entry_pos));
@@ -4909,15 +4909,15 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         }
     }
 
-    st->internal->nb_index_entries += entries;
-    sc->ctts_count = st->internal->nb_index_entries;
+    st->nb_index_entries += entries;
+    sc->ctts_count = st->nb_index_entries;
 
     // Record the index_entry position in frag_index of this fragment
     if (frag_stream_info)
         frag_stream_info->index_entry = index_entry_pos;
 
     if (index_entry_pos > 0)
-        prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp;
+        prev_dts = st->index_entries[index_entry_pos-1].timestamp;
 
     for (i = 0; i < entries && !pb->eof_reached; i++) {
         unsigned sample_size = frag->size;
@@ -4966,11 +4966,11 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         if (prev_dts >= dts)
             index_entry_flags |= AVINDEX_DISCARD_FRAME;
 
-        st->internal->index_entries[index_entry_pos].pos = offset;
-        st->internal->index_entries[index_entry_pos].timestamp = dts;
-        st->internal->index_entries[index_entry_pos].size= sample_size;
-        st->internal->index_entries[index_entry_pos].min_distance= distance;
-        st->internal->index_entries[index_entry_pos].flags = index_entry_flags;
+        st->index_entries[index_entry_pos].pos = offset;
+        st->index_entries[index_entry_pos].timestamp = dts;
+        st->index_entries[index_entry_pos].size= sample_size;
+        st->index_entries[index_entry_pos].min_distance= distance;
+        st->index_entries[index_entry_pos].flags = index_entry_flags;
 
         sc->ctts_data[index_entry_pos].count = 1;
         sc->ctts_data[index_entry_pos].duration = ctts_duration;
@@ -4997,16 +4997,16 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         // EOF found before reading all entries.  Fix the hole this would
         // leave in index_entries and ctts_data
         int gap = entries - i;
-        memmove(st->internal->index_entries + index_entry_pos,
-                st->internal->index_entries + index_entry_pos + gap,
-                sizeof(*st->internal->index_entries) *
-                (st->internal->nb_index_entries - (index_entry_pos + gap)));
+        memmove(st->index_entries + index_entry_pos,
+                st->index_entries + index_entry_pos + gap,
+                sizeof(*st->index_entries) *
+                (st->nb_index_entries - (index_entry_pos + gap)));
         memmove(sc->ctts_data + index_entry_pos,
                 sc->ctts_data + index_entry_pos + gap,
                 sizeof(*sc->ctts_data) *
                 (sc->ctts_count - (index_entry_pos + gap)));
 
-        st->internal->nb_index_entries -= gap;
+        st->nb_index_entries -= gap;
         sc->ctts_count -= gap;
         if (index_entry_pos < sc->current_sample) {
             sc->current_sample -= gap;
@@ -5019,11 +5019,11 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     // fragment that overlap with AVINDEX_DISCARD_FRAME
     prev_dts = AV_NOPTS_VALUE;
     if (index_entry_pos > 0)
-        prev_dts = st->internal->index_entries[index_entry_pos-1].timestamp;
-    for (i = index_entry_pos; i < st->internal->nb_index_entries; i++) {
-        if (prev_dts < st->internal->index_entries[i].timestamp)
+        prev_dts = st->index_entries[index_entry_pos-1].timestamp;
+    for (i = index_entry_pos; i < st->nb_index_entries; i++) {
+        if (prev_dts < st->index_entries[i].timestamp)
             break;
-        st->internal->index_entries[i].flags |= AVINDEX_DISCARD_FRAME;
+        st->index_entries[i].flags |= AVINDEX_DISCARD_FRAME;
     }
 
     // If a hole was created to insert the new index_entries into,
@@ -7221,9 +7221,9 @@  static void mov_read_chapters(AVFormatContext *s)
 
         if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
             st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS;
-            if (st->internal->nb_index_entries) {
+            if (st->nb_index_entries) {
                 // Retrieve the first frame, if possible
-                AVIndexEntry *sample = &st->internal->index_entries[0];
+                AVIndexEntry *sample = &st->index_entries[0];
                 if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
                     av_log(s, AV_LOG_ERROR, "Failed to retrieve first frame\n");
                     goto finish;
@@ -7239,9 +7239,9 @@  static void mov_read_chapters(AVFormatContext *s)
             st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
             st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA;
             st->discard = AVDISCARD_ALL;
-            for (i = 0; i < st->internal->nb_index_entries; i++) {
-                AVIndexEntry *sample = &st->internal->index_entries[i];
-                int64_t end = i+1 < st->internal->nb_index_entries ? st->internal->index_entries[i+1].timestamp : st->duration;
+            for (i = 0; i < st->nb_index_entries; i++) {
+                AVIndexEntry *sample = &st->index_entries[i];
+                int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
                 uint8_t *title;
                 uint16_t ch;
                 int len, title_len;
@@ -7314,10 +7314,10 @@  static int mov_read_rtmd_track(AVFormatContext *s, AVStream *st)
     int64_t cur_pos = avio_tell(sc->pb);
     int hh, mm, ss, ff, drop;
 
-    if (!st->internal->nb_index_entries)
+    if (!st->nb_index_entries)
         return -1;
 
-    avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET);
+    avio_seek(sc->pb, st->index_entries->pos, SEEK_SET);
     avio_skip(s->pb, 13);
     hh = avio_r8(s->pb);
     mm = avio_r8(s->pb);
@@ -7339,10 +7339,10 @@  static int mov_read_timecode_track(AVFormatContext *s, AVStream *st)
     int64_t cur_pos = avio_tell(sc->pb);
     uint32_t value;
 
-    if (!st->internal->nb_index_entries)
+    if (!st->nb_index_entries)
         return -1;
 
-    avio_seek(sc->pb, st->internal->index_entries->pos, SEEK_SET);
+    avio_seek(sc->pb, st->index_entries->pos, SEEK_SET);
     value = avio_rb32(s->pb);
 
     if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME;
@@ -7807,8 +7807,8 @@  static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *avst = s->streams[i];
         MOVStreamContext *msc = avst->priv_data;
-        if (msc->pb && msc->current_sample < avst->internal->nb_index_entries) {
-            AVIndexEntry *current_sample = &avst->internal->index_entries[msc->current_sample];
+        if (msc->pb && msc->current_sample < avst->nb_index_entries) {
+            AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample];
             int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
             av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
             if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) ||
@@ -8011,8 +8011,8 @@  static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
             sc->ctts_sample = 0;
         }
     } else {
-        int64_t next_dts = (sc->current_sample < st->internal->nb_index_entries) ?
-            st->internal->index_entries[sc->current_sample].timestamp : st->duration;
+        int64_t next_dts = (sc->current_sample < st->nb_index_entries) ?
+            st->index_entries[sc->current_sample].timestamp : st->duration;
 
         if (next_dts >= pkt->dts)
             pkt->duration = next_dts - pkt->dts;
@@ -8093,7 +8093,7 @@  static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
 
     sample = av_index_search_timestamp(st, timestamp, flags);
     av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);
-    if (sample < 0 && st->internal->nb_index_entries && timestamp < st->internal->index_entries[0].timestamp)
+    if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
         sample = 0;
     if (sample < 0) /* not sure what to do */
         return AVERROR_INVALIDDATA;
@@ -8134,8 +8134,8 @@  static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
 static int64_t mov_get_skip_samples(AVStream *st, int sample)
 {
     MOVStreamContext *sc = st->priv_data;
-    int64_t first_ts = st->internal->index_entries[0].timestamp;
-    int64_t ts = st->internal->index_entries[sample].timestamp;
+    int64_t first_ts = st->index_entries[0].timestamp;
+    int64_t ts = st->index_entries[sample].timestamp;
     int64_t off;
 
     if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
@@ -8164,7 +8164,7 @@  static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti
 
     if (mc->seek_individually) {
         /* adjust seek timestamp to found sample timestamp */
-        int64_t seek_timestamp = st->internal->index_entries[sample].timestamp;
+        int64_t seek_timestamp = st->index_entries[sample].timestamp;
         st->internal->skip_samples = mov_get_skip_samples(st, sample);
 
         for (i = 0; i < s->nb_streams; i++) {
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 53f803ef55..5e7f273c6a 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -431,8 +431,8 @@  static int mp3_read_header(AVFormatContext *s)
     }
 
     // the seek index is relative to the end of the xing vbr headers
-    for (i = 0; i < st->internal->nb_index_entries; i++)
-        st->internal->index_entries[i].pos += avio_tell(s->pb);
+    for (i = 0; i < st->nb_index_entries; i++)
+        st->index_entries[i].pos += avio_tell(s->pb);
 
     /* the parameters will be extracted from the compressed bitstream */
     return 0;
@@ -567,7 +567,7 @@  static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
         if (ret < 0)
             return ret;
 
-        ie = &st->internal->index_entries[ret];
+        ie = &st->index_entries[ret];
     } else if (fast_seek && st->duration > 0 && filesize > 0) {
         if (!mp3->is_cbr)
             av_log(s, AV_LOG_WARNING, "Using scaling to seek VBR MP3; may be imprecise.\n");
diff --git a/libavformat/mpc.c b/libavformat/mpc.c
index 31a2072406..6a94b5d1d0 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -194,8 +194,8 @@  static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
     uint32_t lastframe;
 
     /* if found, seek there */
-    if (index >= 0 && st->internal->index_entries[st->internal->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){
-        c->curframe = st->internal->index_entries[index].pos;
+    if (index >= 0 && st->index_entries[st->nb_index_entries-1].timestamp >= timestamp - DELAY_FRAMES){
+        c->curframe = st->index_entries[index].pos;
         return 0;
     }
     /* if timestamp is out of bounds, return error */
diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c
index ff7da2ef55..f33323a599 100644
--- a/libavformat/mpc8.c
+++ b/libavformat/mpc8.c
@@ -314,9 +314,9 @@  static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestam
     int index = av_index_search_timestamp(st, timestamp, flags);
 
     if(index < 0) return -1;
-    if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
+    if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
         return -1;
-    ff_update_cur_dts(s, st, st->internal->index_entries[index].timestamp);
+    ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
     return 0;
 }
 
diff --git a/libavformat/mux.c b/libavformat/mux.c
index e98b86a81e..6a557d294e 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1308,7 +1308,7 @@  int av_write_trailer(AVFormatContext *s)
        ret = s->pb ? s->pb->error : 0;
     for (i = 0; i < s->nb_streams; i++) {
         av_freep(&s->streams[i]->priv_data);
-        av_freep(&s->streams[i]->internal->index_entries);
+        av_freep(&s->streams[i]->index_entries);
     }
     if (s->oformat->priv_class)
         av_opt_free(s->priv_data);
diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
index 2aef93a735..045c66ac3c 100644
--- a/libavformat/mvdec.c
+++ b/libavformat/mvdec.c
@@ -438,8 +438,8 @@  static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     int64_t ret;
     uint64_t pos;
 
-    if (frame < st->internal->nb_index_entries) {
-        index = &st->internal->index_entries[frame];
+    if (frame < st->nb_index_entries) {
+        index = &st->index_entries[frame];
         pos   = avio_tell(pb);
         if (index->pos > pos)
             avio_skip(pb, index->pos - pos);
diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c
index 4fab52ed36..eb26b29450 100644
--- a/libavformat/nsvdec.c
+++ b/libavformat/nsvdec.c
@@ -682,10 +682,10 @@  static int nsv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
     if(index < 0)
         return -1;
 
-    if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
+    if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
         return -1;
 
-    nst->frame_offset = st->internal->index_entries[index].timestamp;
+    nst->frame_offset = st->index_entries[index].timestamp;
     nsv->state = NSV_UNSYNC;
     return 0;
 }
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index d1f3496990..fbecf71328 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -1235,15 +1235,15 @@  static int read_seek(AVFormatContext *s, int stream_index,
         return AVERROR(ENOSYS);
     }
 
-    if (st->internal->index_entries) {
+    if (st->index_entries) {
         int index = av_index_search_timestamp(st, pts, flags);
         if (index < 0)
             index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD);
         if (index < 0)
             return -1;
 
-        pos2 = st->internal->index_entries[index].pos;
-        ts   = st->internal->index_entries[index].timestamp;
+        pos2 = st->index_entries[index].pos;
+        ts   = st->index_entries[index].timestamp;
     } else {
         av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp,
                      (void **) next_node);
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 1dcb2be1b1..6d3bf6c21e 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -1013,12 +1013,12 @@  static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
             int index = av_index_search_timestamp(st, dts_tb,
                                                   AVSEEK_FLAG_BACKWARD);
             if (index >= 0) {
-                sp_pos = FFMIN(sp_pos, st->internal->index_entries[index].pos);
-                if (!nut->write_index && 2*index > st->internal->nb_index_entries) {
-                    memmove(st->internal->index_entries,
-                            st->internal->index_entries + index,
-                            sizeof(*st->internal->index_entries) * (st->internal->nb_index_entries - index));
-                    st->internal->nb_index_entries -=  index;
+                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;
                 }
             }
         }
diff --git a/libavformat/rl2.c b/libavformat/rl2.c
index fa1b38b133..cfde23a945 100644
--- a/libavformat/rl2.c
+++ b/libavformat/rl2.c
@@ -237,9 +237,9 @@  static int rl2_read_packet(AVFormatContext *s,
 
     /** check if there is a valid video or audio entry that can be used */
     for(i=0; i<s->nb_streams; i++){
-        if(rl2->index_pos[i] < s->streams[i]->internal->nb_index_entries
-              && s->streams[i]->internal->index_entries[ rl2->index_pos[i] ].pos < pos){
-            sample = &s->streams[i]->internal->index_entries[ rl2->index_pos[i] ];
+        if(rl2->index_pos[i] < s->streams[i]->nb_index_entries
+              && s->streams[i]->index_entries[ rl2->index_pos[i] ].pos < pos){
+            sample = &s->streams[i]->index_entries[ rl2->index_pos[i] ];
             pos= sample->pos;
             stream_id= i;
         }
@@ -283,7 +283,7 @@  static int rl2_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
         return -1;
 
     rl2->index_pos[stream_index] = index;
-    timestamp = st->internal->index_entries[index].timestamp;
+    timestamp = st->index_entries[index].timestamp;
 
     for(i=0; i < s->nb_streams; i++){
         AVStream *st2 = s->streams[i];
diff --git a/libavformat/rpl.c b/libavformat/rpl.c
index b98488c7b1..0f00c03a52 100644
--- a/libavformat/rpl.c
+++ b/libavformat/rpl.c
@@ -317,10 +317,10 @@  static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     stream = s->streams[rpl->chunk_part];
 
-    if (rpl->chunk_number >= stream->internal->nb_index_entries)
+    if (rpl->chunk_number >= stream->nb_index_entries)
         return AVERROR_EOF;
 
-    index_entry = &stream->internal->index_entries[rpl->chunk_number];
+    index_entry = &stream->index_entries[rpl->chunk_number];
 
     if (rpl->frame_in_part == 0)
         if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0)
diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 1225227138..91cd7b7c2b 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -324,7 +324,7 @@  static int film_read_seek(AVFormatContext *s, int stream_index, int64_t timestam
     if (ret < 0)
         return ret;
 
-    pos = avio_seek(s->pb, st->internal->index_entries[ret].pos, SEEK_SET);
+    pos = avio_seek(s->pb, st->index_entries[ret].pos, SEEK_SET);
     if (pos < 0)
         return pos;
 
diff --git a/libavformat/tta.c b/libavformat/tta.c
index 46c2508bce..07faa82eb3 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -155,15 +155,15 @@  static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (c->currentframe >= c->totalframes)
         return AVERROR_EOF;
 
-    if (st->internal->nb_index_entries < c->totalframes) {
+    if (st->nb_index_entries < c->totalframes) {
         av_log(s, AV_LOG_ERROR, "Index entry disappeared\n");
         return AVERROR_INVALIDDATA;
     }
 
-    size = st->internal->index_entries[c->currentframe].size;
+    size = st->index_entries[c->currentframe].size;
 
     ret = av_get_packet(s->pb, pkt, size);
-    pkt->dts = st->internal->index_entries[c->currentframe++].timestamp;
+    pkt->dts = st->index_entries[c->currentframe++].timestamp;
     pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size :
                                                         c->frame_size;
     return ret;
@@ -176,7 +176,7 @@  static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
     int index = av_index_search_timestamp(st, timestamp, flags);
     if (index < 0)
         return -1;
-    if (avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET) < 0)
+    if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0)
         return -1;
 
     c->currentframe = index;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 295e676c9c..6ae87f7b9f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1941,11 +1941,11 @@  void ff_reduce_index(AVFormatContext *s, int stream_index)
     AVStream *st             = s->streams[stream_index];
     unsigned int max_entries = s->max_index_size / sizeof(AVIndexEntry);
 
-    if ((unsigned) st->internal->nb_index_entries >= max_entries) {
+    if ((unsigned) st->nb_index_entries >= max_entries) {
         int i;
-        for (i = 0; 2 * i < st->internal->nb_index_entries; i++)
-            st->internal->index_entries[i] = st->internal->index_entries[2 * i];
-        st->internal->nb_index_entries = i;
+        for (i = 0; 2 * i < st->nb_index_entries; i++)
+            st->index_entries[i] = st->index_entries[2 * i];
+        st->nb_index_entries = i;
     }
 }
 
@@ -2012,8 +2012,8 @@  int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
                        int size, int distance, int flags)
 {
     timestamp = wrap_timestamp(st, timestamp);
-    return ff_add_index_entry(&st->internal->index_entries, &st->internal->nb_index_entries,
-                              &st->internal->index_entries_allocated_size, pos,
+    return ff_add_index_entry(&st->index_entries, &st->nb_index_entries,
+                              &st->index_entries_allocated_size, pos,
                               timestamp, size, distance, flags);
 }
 
@@ -2089,13 +2089,13 @@  void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
             if (ist1 == ist2)
                 continue;
 
-            for (i1 = i2 = 0; i1 < st1->internal->nb_index_entries; i1++) {
-                AVIndexEntry *e1 = &st1->internal->index_entries[i1];
+            for (i1 = i2 = 0; i1 < st1->nb_index_entries; i1++) {
+                AVIndexEntry *e1 = &st1->index_entries[i1];
                 int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q);
 
                 skip = FFMAX(skip, e1->size);
-                for (; i2 < st2->internal->nb_index_entries; i2++) {
-                    AVIndexEntry *e2 = &st2->internal->index_entries[i2];
+                for (; i2 < st2->nb_index_entries; i2++) {
+                    AVIndexEntry *e2 = &st2->index_entries[i2];
                     int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
                     if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
                         continue;
@@ -2127,7 +2127,7 @@  void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
 
 int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)
 {
-    return ff_index_search_timestamp(st->internal->index_entries, st->internal->nb_index_entries,
+    return ff_index_search_timestamp(st->index_entries, st->nb_index_entries,
                                      wanted_timestamp, flags);
 }
 
@@ -2160,7 +2160,7 @@  int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
     pos_limit = -1; // GCC falsely says it may be uninitialized.
 
     st = s->streams[stream_index];
-    if (st->internal->index_entries) {
+    if (st->index_entries) {
         AVIndexEntry *e;
 
         /* FIXME: Whole function must be checked for non-keyframe entries in
@@ -2168,7 +2168,7 @@  int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
         index = av_index_search_timestamp(st, target_ts,
                                           flags | AVSEEK_FLAG_BACKWARD);
         index = FFMAX(index, 0);
-        e     = &st->internal->index_entries[index];
+        e     = &st->index_entries[index];
 
         if (e->timestamp <= target_ts || e->pos == e->min_distance) {
             pos_min = e->pos;
@@ -2181,9 +2181,9 @@  int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
 
         index = av_index_search_timestamp(st, target_ts,
                                           flags & ~AVSEEK_FLAG_BACKWARD);
-        av_assert0(index < st->internal->nb_index_entries);
+        av_assert0(index < st->nb_index_entries);
         if (index >= 0) {
-            e = &st->internal->index_entries[index];
+            e = &st->index_entries[index];
             av_assert1(e->timestamp >= target_ts);
             pos_max   = e->pos;
             ts_max    = e->timestamp;
@@ -2384,17 +2384,17 @@  static int seek_frame_generic(AVFormatContext *s, int stream_index,
 
     index = av_index_search_timestamp(st, timestamp, flags);
 
-    if (index < 0 && st->internal->nb_index_entries &&
-        timestamp < st->internal->index_entries[0].timestamp)
+    if (index < 0 && st->nb_index_entries &&
+        timestamp < st->index_entries[0].timestamp)
         return -1;
 
-    if (index < 0 || index == st->internal->nb_index_entries - 1) {
+    if (index < 0 || index == st->nb_index_entries - 1) {
         AVPacket *pkt = s->internal->pkt;
         int nonkey = 0;
 
-        if (st->internal->nb_index_entries) {
-            av_assert0(st->internal->index_entries);
-            ie = &st->internal->index_entries[st->internal->nb_index_entries - 1];
+        if (st->nb_index_entries) {
+            av_assert0(st->index_entries);
+            ie = &st->index_entries[st->nb_index_entries - 1];
             if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
                 return ret;
             ff_update_cur_dts(s, st, ie->timestamp);
@@ -2432,7 +2432,7 @@  static int seek_frame_generic(AVFormatContext *s, int stream_index,
     if (s->iformat->read_seek)
         if (s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)
             return 0;
-    ie = &st->internal->index_entries[index];
+    ie = &st->index_entries[index];
     if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
         return ret;
     ff_update_cur_dts(s, st, ie->timestamp);
@@ -4391,7 +4391,7 @@  static void free_stream(AVStream **pst)
         avcodec_free_context(&st->internal->avctx);
         av_bsf_free(&st->internal->bsfc);
         av_freep(&st->internal->priv_pts);
-        av_freep(&st->internal->index_entries);
+        av_freep(&st->index_entries);
         av_freep(&st->internal->probe_data.buf);
 
         av_bsf_free(&st->internal->extract_extradata.bsf);
diff --git a/libavformat/vocdec.c b/libavformat/vocdec.c
index 6cdc720ee7..2ccabf0fa8 100644
--- a/libavformat/vocdec.c
+++ b/libavformat/vocdec.c
@@ -83,14 +83,14 @@  static int voc_read_seek(AVFormatContext *s, int stream_index,
     st = s->streams[stream_index];
     index = av_index_search_timestamp(st, timestamp, flags);
 
-    if (index >= 0 && index < st->internal->nb_index_entries - 1) {
-        AVIndexEntry *e = &st->internal->index_entries[index];
+    if (index >= 0 && index < st->nb_index_entries - 1) {
+        AVIndexEntry *e = &st->index_entries[index];
         avio_seek(s->pb, e->pos, SEEK_SET);
         voc->pts = e->timestamp;
         voc->remaining_size = e->size;
         return 0;
-    } else if (st->internal->nb_index_entries && st->internal->index_entries[0].timestamp <= timestamp) {
-        AVIndexEntry *e = &st->internal->index_entries[st->internal->nb_index_entries - 1];
+    } else if (st->nb_index_entries && st->index_entries[0].timestamp <= timestamp) {
+        AVIndexEntry *e = &st->index_entries[st->nb_index_entries - 1];
         // prepare context for seek_frame_generic()
         voc->pts = e->timestamp;
         voc->remaining_size = e->size;