X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Futils.c;h=333baa02903117719036ad7841dc2c4328d94550;hb=39f6733f0593064ae5148dd6484f1d7c74d7cae5;hp=c7eb93f3b0cdfc5f796d090a9edc37e98fab360d;hpb=52673ab18a8f241e37aea83236ffe0fa84b78655;p=ffmpeg diff --git a/libavformat/utils.c b/libavformat/utils.c index c7eb93f3b0c..333baa02903 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1902,7 +1902,7 @@ static int has_duration(AVFormatContext *ic) static void update_stream_timings(AVFormatContext *ic) { int64_t start_time, start_time1, start_time_text, end_time, end_time1; - int64_t duration, duration1; + int64_t duration, duration1, filesize; int i; AVStream *st; @@ -1945,9 +1945,9 @@ static void update_stream_timings(AVFormatContext *ic) if (duration != INT64_MIN && ic->duration == AV_NOPTS_VALUE) { ic->duration = duration; } - if (ic->file_size > 0 && ic->duration != AV_NOPTS_VALUE) { + if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration != AV_NOPTS_VALUE) { /* compute the bitrate */ - ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / + ic->bit_rate = (double)filesize * 8.0 * AV_TIME_BASE / (double)ic->duration; } } @@ -1988,9 +1988,8 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) /* if duration is already set, we believe it */ if (ic->duration == AV_NOPTS_VALUE && - ic->bit_rate != 0 && - ic->file_size != 0) { - filesize = ic->file_size; + ic->bit_rate != 0) { + filesize = ic->pb ? avio_size(ic->pb) : 0; if (filesize > 0) { for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; @@ -2034,7 +2033,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* estimate the end time (duration) */ /* XXX: may need to support wrapping */ - filesize = ic->file_size; + filesize = ic->pb ? avio_size(ic->pb) : 0; end_time = AV_NOPTS_VALUE; do{ offset = filesize - (DURATION_MAX_READ_SIZE<file_size = file_size; if ((!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) &&