[FFmpeg-devel] [PATCH 1/1] Trying to fix trac ticket #7359

Nick Ryan nick.paul.ryan at gmail.com
Wed Sep 26 16:33:01 EEST 2018


Signed-off-by: Nick Ryan <nick.paul.ryan at gmail.com>
---
 libavformat/mov.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 67015a72a1..587513e06e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7605,15 +7605,15 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index)
 
     if (index >= 0 && index < mov->frag_index.nb_items)
         target = mov->frag_index.item[index].moof_offset;
-    if (avio_seek(s->pb, target, SEEK_SET) != target) {
+    if (target >= 0 && avio_seek(s->pb, target, SEEK_SET) != target) {
         av_log(mov->fc, AV_LOG_ERROR, "root atom offset 0x%"PRIx64": partial file\n", target);
         return AVERROR_INVALIDDATA;
     }
 
     mov->next_root_atom = 0;
-    if (index < 0 || index >= mov->frag_index.nb_items)
+    if ((index < 0 && target >= 0) || index >= mov->frag_index.nb_items)
         index = search_frag_moof_offset(&mov->frag_index, target);
-    if (index < mov->frag_index.nb_items) {
+    if (index >= 0 && index < mov->frag_index.nb_items) {
         if (index + 1 < mov->frag_index.nb_items)
             mov->next_root_atom = mov->frag_index.item[index + 1].moof_offset;
         if (mov->frag_index.item[index].headers_read)
@@ -7663,9 +7663,22 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
     AVIndexEntry *sample;
     AVStream *st = NULL;
     int64_t current_index;
+    int i;
     int ret;
     mov->fc = s;
  retry:
+    if (s->pb->pos == 0) {
+        mov->frag_index.nb_items = 0;
+        mov->frag_index.current = -1;
+        for (i = 0; i < s->nb_streams; i++) {
+            AVStream *avst = s->streams[i];
+            avst->index_entries = NULL;
+            avst->index_entries_allocated_size = 0;
+            avst->nb_index_entries = 0;
+        }
+        if ((ret = mov_switch_root(s, -1, -1)) < 0)
+            return ret;
+    }
     sample = mov_find_next_sample(s, &st);
     if (!sample || (mov->next_root_atom && sample->pos > mov->next_root_atom)) {
         if (!mov->next_root_atom)
-- 
2.17.1 (Apple Git-112)



More information about the ffmpeg-devel mailing list