[FFmpeg-cvslog] avcodec: add duration field to AVCodecParserContext

Justin Ruggles git at videolan.org
Tue Feb 21 05:29:40 CET 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Jan 12 20:03:17 2012 -0500| [e9cda853511d7c5a8fa16da4f99cf8ead86bf658] | committer: Justin Ruggles

avcodec: add duration field to AVCodecParserContext

This will allow parsers to export the duration of the current frame being
output, if known, instead of using AVCodecContext.frame_size.

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

 doc/APIchanges       |    3 +++
 libavcodec/avcodec.h |    7 +++++++
 libavformat/utils.c  |   14 ++++++++++++++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index ca521d4..12fa803 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2012-xx-xx - xxxxxxx - lavc 54.x.x
+  Add duration field to AVCodecParserContext
+
 2012-02-xx - xxxxxxx - lavu 51.23.1 - mathematics.h
   Add av_rescale_q_rnd()
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 51b956b..7128a83 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3994,6 +3994,13 @@ typedef struct AVCodecParserContext {
      * Previous frame byte position.
      */
     int64_t last_pos;
+
+    /**
+     * Duration of the current frame.
+     * For audio, this is in units of 1 / AVCodecContext.sample_rate.
+     * For all other types, this is in units of AVCodecContext.time_base.
+     */
+    int duration;
 } AVCodecParserContext;
 
 typedef struct AVCodecParser {
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 33775b9..2417522 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1039,6 +1039,20 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 if (pkt->size) {
                 got_packet:
                     pkt->duration = 0;
+                    if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+                        if (st->codec->sample_rate > 0) {
+                            pkt->duration = av_rescale_q_rnd(st->parser->duration,
+                                                             (AVRational){ 1, st->codec->sample_rate },
+                                                             st->time_base,
+                                                             AV_ROUND_DOWN);
+                        }
+                    } else if (st->codec->time_base.num != 0 &&
+                               st->codec->time_base.den != 0) {
+                        pkt->duration = av_rescale_q_rnd(st->parser->duration,
+                                                         st->codec->time_base,
+                                                         st->time_base,
+                                                         AV_ROUND_DOWN);
+                    }
                     pkt->stream_index = st->index;
                     pkt->pts = st->parser->pts;
                     pkt->dts = st->parser->dts;



More information about the ffmpeg-cvslog mailing list