[FFmpeg-cvslog] avformat/mov: redesign the fps calculation
Michael Niedermayer
git at videolan.org
Wed Jan 22 00:40:28 CET 2014
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Jan 22 00:33:38 2014 +0100| [28bc1d94b739d8273caad49641f8335240972cbf] | committer: Michael Niedermayer
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 at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=28bc1d94b739d8273caad49641f8335240972cbf
---
libavformat/isom.h | 3 +++
libavformat/mov.c | 12 ++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 2834b11..a929ebf 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 a24df84..f07c6b3 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) {
More information about the ffmpeg-cvslog
mailing list