[FFmpeg-cvslog] lavf: switch to AVCodecContext.framerate for demuxing

Anton Khirnov git at videolan.org
Wed Oct 15 18:29:15 CEST 2014


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Oct  8 19:23:14 2014 +0000| [2d6e58497e76836604364b037df9b00ba3d75b69] | committer: Anton Khirnov

lavf: switch to AVCodecContext.framerate for demuxing

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2d6e58497e76836604364b037df9b00ba3d75b69
---

 libavformat/internal.h |    2 +-
 libavformat/mux.c      |    2 +-
 libavformat/utils.c    |   14 ++++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 9921ce1..c66a045 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -323,7 +323,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
 /**
  * Return the frame duration in seconds. Return 0 if not available.
  */
-void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st,
+void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st,
                                AVCodecParserContext *pc, AVPacket *pkt);
 
 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 3b11e4e..4067c16 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -265,7 +265,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
 
     /* duration field */
     if (pkt->duration == 0) {
-        ff_compute_frame_duration(&num, &den, st, NULL, pkt);
+        ff_compute_frame_duration(s, &num, &den, st, NULL, pkt);
         if (den && num) {
             pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
         }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ffad92f..ef2d89f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -456,9 +456,11 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
 /**
  * Return the frame duration in seconds. Return 0 if not available.
  */
-void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st,
+void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st,
                                AVCodecParserContext *pc, AVPacket *pkt)
 {
+    AVRational codec_framerate = s->iformat ? st->codec->framerate :
+                                              av_inv_q(st->codec->time_base);
     int frame_size;
 
     *pnum = 0;
@@ -471,9 +473,9 @@ void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st,
         } else if (st->time_base.num * 1000LL > st->time_base.den) {
             *pnum = st->time_base.num;
             *pden = st->time_base.den;
-        } else if (st->codec->time_base.num * 1000LL > st->codec->time_base.den) {
-            *pnum = st->codec->time_base.num;
-            *pden = st->codec->time_base.den;
+        } else if (codec_framerate.den * 1000LL > codec_framerate.num) {
+            *pnum = codec_framerate.den;
+            *pden = codec_framerate.num;
             if (pc && pc->repeat_pict) {
                 if (*pnum > INT_MAX / (1 + pc->repeat_pict))
                     *pden /= 1 + pc->repeat_pict;
@@ -620,7 +622,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
     }
 
     if (pkt->duration == 0 && st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
-        ff_compute_frame_duration(&num, &den, st, pc, pkt);
+        ff_compute_frame_duration(s, &num, &den, st, pc, pkt);
         if (den && num) {
             pkt->duration = av_rescale_rnd(1, num * (int64_t) st->time_base.den,
                                            den * (int64_t) st->time_base.num,
@@ -683,7 +685,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
                    st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
             int duration = pkt->duration;
             if (!duration && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-                ff_compute_frame_duration(&num, &den, st, pc, pkt);
+                ff_compute_frame_duration(s, &num, &den, st, pc, pkt);
                 if (den && num) {
                     duration = av_rescale_rnd(1,
                                               num * (int64_t) st->time_base.den,



More information about the ffmpeg-cvslog mailing list