summaryrefslogtreecommitdiff
path: root/libavformat/flvdec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2006-12-10 17:53:01 +0000
committerMichael Niedermayer <michaelni@gmx.at>2006-12-10 17:53:01 +0000
commit15f14fc7c20914f388f85163ed3a27f80ff27301 (patch)
tree1f7c8e60fd831ff4b49dab5baffe70814e36e311 /libavformat/flvdec.c
parent17fcb1709fd04433a05c6f60023856eebf817dd5 (diff)
move duration finding code into read_packet() so it can be skiped if duration has already been set
Originally committed as revision 7272 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/flvdec.c')
-rw-r--r--libavformat/flvdec.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index c49fe8eae7..2906b1d4ec 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -57,7 +57,7 @@ static int amf_get_string(ByteIOContext *ioc, char *buffer, int buffsize) {
static int flv_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
- int offset, flags, size;
+ int offset, flags;
AVStream *st;
url_fskip(&s->pb, 4);
@@ -79,17 +79,6 @@ static int flv_read_header(AVFormatContext *s,
}
offset = get_be32(&s->pb);
-
- if(!url_is_streamed(&s->pb)){
- const int fsize= url_fsize(&s->pb);
- url_fseek(&s->pb, fsize-4, SEEK_SET);
- size= get_be32(&s->pb);
- url_fseek(&s->pb, fsize-3-size, SEEK_SET);
- if(size == get_be24(&s->pb) + 11){
- s->duration= get_be24(&s->pb) * (int64_t)AV_TIME_BASE / 1000;
- }
- }
-
url_fseek(&s->pb, offset, SEEK_SET);
s->start_time = 0;
@@ -190,6 +179,20 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
break;
}
+ // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps
+ if(!url_is_streamed(&s->pb) && s->duration==AV_NOPTS_VALUE){
+ int size;
+ const int pos= url_ftell(&s->pb);
+ const int fsize= url_fsize(&s->pb);
+ url_fseek(&s->pb, fsize-4, SEEK_SET);
+ size= get_be32(&s->pb);
+ url_fseek(&s->pb, fsize-3-size, SEEK_SET);
+ if(size == get_be24(&s->pb) + 11){
+ s->duration= get_be24(&s->pb) * (int64_t)AV_TIME_BASE / 1000;
+ }
+ url_fseek(&s->pb, pos, SEEK_SET);
+ }
+
if(is_audio){
if(st->codec->sample_rate == 0){
st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;