]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/wtvdec.c
ffmpeg: preserve avg_frame_rate on stream copy.
[ffmpeg] / libavformat / wtvdec.c
index e27fa14a6af2385df83837cfef50e6aac03822b0..543fcb68d27e7b46b8854b2d7f11253ef1d84379 100644 (file)
@@ -414,7 +414,7 @@ static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length)
     if (!filesize)
         goto done;
 
-    st = av_new_stream(s, 0);
+    st = avformat_new_stream(s, NULL);
     if (!st)
         goto done;
     av_dict_set(&st->metadata, "title", description, 0);
@@ -562,9 +562,10 @@ static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int code
         WtvStream *wst = av_mallocz(sizeof(WtvStream));
         if (!wst)
             return NULL;
-        st = av_new_stream(s, sid);
+        st = avformat_new_stream(s, NULL);
         if (!st)
             return NULL;
+        st->id = sid;
         st->priv_data = wst;
     }
     st->codec->codec_type = codec_type;
@@ -772,7 +773,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
                 buf_size = FFMIN(len - consumed, sizeof(buf));
                 avio_read(pb, buf, buf_size);
                 consumed += buf_size;
-                ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, 0, 0, 0, 0);
+                ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, NULL, 0, 0, NULL);
             }
         } else if (!ff_guidcmp(g, EVENTID_AudioTypeSpanningEvent)) {
             int stream_index = ff_find_stream_index(s, sid);
@@ -997,19 +998,23 @@ static int read_seek(AVFormatContext *s, int stream_index,
 
     i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags);
     if (i < 0) {
-        if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts)
-            avio_seek(pb, 0, SEEK_SET);
-        else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)
-            avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);
+        if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts) {
+            if (avio_seek(pb, 0, SEEK_SET) < 0)
+                return -1;
+        } else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries) {
+            if (avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET) < 0)
+                return -1;
+        }
         if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)
             return AVERROR(ERANGE);
         return 0;
     }
+    if (avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET) < 0)
+        return -1;
     wtv->pts = wtv->index_entries[i].timestamp;
     if (wtv->epoch != AV_NOPTS_VALUE)
         wtv->pts += wtv->epoch;
     wtv->last_valid_pts = wtv->pts;
-    avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);
     return 0;
 }