summaryrefslogtreecommitdiff
path: root/libavformat/flvdec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-08-03 14:41:18 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-08-03 14:50:26 +0200
commit231ffb9243e5286b7c3d5806fa8f3142c72bfe15 (patch)
tree070c8e14151939b6bd3abf1a6560ac7580508955 /libavformat/flvdec.c
parent71a5cd7dbc681ef22e994b92412a8c1a088a2841 (diff)
flvdec: follow packets backward until a valid last timestamp is found
Fixed Ticket981 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/flvdec.c')
-rw-r--r--libavformat/flvdec.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index fb356b801b..2c342bbddb 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -748,15 +748,22 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE) && !flv->searched_for_end){
int size;
const int64_t pos= avio_tell(s->pb);
- const int64_t fsize= avio_size(s->pb);
+ int64_t fsize= avio_size(s->pb);
+retry_duration:
avio_seek(s->pb, fsize-4, SEEK_SET);
size= avio_rb32(s->pb);
avio_seek(s->pb, fsize-3-size, SEEK_SET);
if(size == avio_rb24(s->pb) + 11){
uint32_t ts = avio_rb24(s->pb);
ts |= avio_r8(s->pb) << 24;
- s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
+ if(ts)
+ s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
+ else if (fsize >= 8 && fsize - 8 >= size){
+ fsize -= size+4;
+ goto retry_duration;
+ }
}
+
avio_seek(s->pb, pos, SEEK_SET);
flv->searched_for_end = 1;
}