diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-22 00:33:38 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-22 00:33:38 +0100 |
commit | 28bc1d94b739d8273caad49641f8335240972cbf (patch) | |
tree | 1c8e757441784825983b763653e5c6736ddcbbed | |
parent | 977abf9aedec429d9c384058a6e3f39a2969b459 (diff) | |
download | ffmpeg-28bc1d94b739d8273caad49641f8335240972cbf.tar.gz |
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>
-rw-r--r-- | libavformat/isom.h | 3 | ||||
-rw-r--r-- | libavformat/mov.c | 12 |
2 files changed, 11 insertions, 4 deletions
diff --git a/libavformat/isom.h b/libavformat/isom.h index 2834b11b3e..a929ebf05e 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -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 { diff --git a/libavformat/mov.c b/libavformat/mov.c index a24df84b54..f07c6b30ce 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -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) { |