Browse Source

avformat/mov: redesign the fps calculation

This uses STTS and TRUN information to calculate the fps
It seems to work with more files than the previous code

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
tags/n2.2-rc1
Michael Niedermayer 12 years ago
parent
commit
28bc1d94b7
2 changed files with 11 additions and 4 deletions
  1. +3
    -0
      libavformat/isom.h
  2. +8
    -4
      libavformat/mov.c

+ 3
- 0
libavformat/isom.h View File

@@ -142,6 +142,9 @@ typedef struct MOVStreamContext {
int start_pad; ///< amount of samples to skip due to enc-dec delay
unsigned int rap_group_count;
MOVSbgp *rap_group;

int nb_frames_for_fps;
int64_t duration_for_fps;
} MOVStreamContext;

typedef struct MOVContext {


+ 8
- 4
libavformat/mov.c View File

@@ -1952,6 +1952,9 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)

sc->stts_count = i;

sc->duration_for_fps += duration;
sc->nb_frames_for_fps += total_sample_count;

if (pb->eof_reached)
return AVERROR_EOF;

@@ -2393,10 +2396,6 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
((double)st->codec->width * sc->height), INT_MAX);
}

if (st->duration > 0)
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
sc->time_scale*st->nb_frames, st->duration, INT_MAX);

#if FF_API_R_FRAME_RATE
if (sc->stts_count == 1 || (sc->stts_count == 2 && sc->stts_data[1].count == 1))
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
@@ -2715,6 +2714,8 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
dts += sample_duration;
offset += sample_size;
sc->data_size += sample_size;
sc->duration_for_fps += sample_duration;
sc->nb_frames_for_fps ++;
}

if (pb->eof_reached)
@@ -3411,6 +3412,9 @@ static int mov_read_header(AVFormatContext *s)
if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->codec_id == AV_CODEC_ID_AAC) {
st->skip_samples = sc->start_pad;
}
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && sc->nb_frames_for_fps > 0 && sc->duration_for_fps > 0)
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
sc->time_scale*sc->nb_frames_for_fps, sc->duration_for_fps, INT_MAX);
}

if (mov->trex_data) {


Loading…
Cancel
Save