1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

nutdec: estimate duration from last syncpoint

Previously nut used the fallback of estimation by bitrate.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-06-30 17:19:43 +02:00
parent e2c95e6bd8
commit 3233ad4b44

View File

@ -31,6 +31,9 @@
#define NUT_MAX_STREAMS 256 /* arbitrary sanity check value */
static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index,
int64_t *pos_arg, int64_t pos_limit);
static int get_str(AVIOContext *bc, char *string, unsigned int maxlen)
{
unsigned int len = ffio_read_varlen(bc);
@ -551,6 +554,23 @@ static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
return 0;
}
//FIXME calculate exactly, this is just a good approximation.
static int64_t find_duration(NUTContext *nut, int64_t filesize)
{
AVFormatContext *s = nut->avf;
int64_t duration = 0;
int64_t pos = FFMAX(0, filesize - 2*nut->max_distance);
for(;;){
int64_t ts = nut_read_timestamp(s, -1, &pos, INT64_MAX);
if(ts < 0)
break;
duration = FFMAX(duration, ts);
pos++;
}
return duration;
}
static int find_and_decode_index(NUTContext *nut)
{
AVFormatContext *s = nut->avf;
@ -569,6 +589,9 @@ static int find_and_decode_index(NUTContext *nut)
avio_seek(bc, filesize - avio_rb64(bc), SEEK_SET);
if (avio_rb64(bc) != INDEX_STARTCODE) {
av_log(s, AV_LOG_ERROR, "no index at the end\n");
if(s->duration<=0)
s->duration = find_duration(nut, filesize);
return -1;
}