This will allow parsers to export the duration of the current frame being
output, if known, instead of using AVCodecContext.frame_size.
---
 doc/APIchanges       |    3 +++
 libavcodec/avcodec.h |    7 +++++++
 libavcodec/version.h |    2 +-
 libavformat/utils.c  |   12 ++++++++++++
 4 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 751566a..bf44a30 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2012-01-xx - xxxxxxx - lavc 53.34.0
+  Add duration field to AVCodecParserContext
+
 2012-01-xx - xxxxxxx - lavfi 2.15.0
   Add a new installed header -- libavfilter/version.h -- with version macros.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c195ad5..9c0b5c7 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4428,6 +4428,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/libavcodec/version.h b/libavcodec/version.h
index 87838c0..d088f0e 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
 #define AVCODEC_VERSION_H
 
 #define LIBAVCODEC_VERSION_MAJOR 53
-#define LIBAVCODEC_VERSION_MINOR 33
+#define LIBAVCODEC_VERSION_MINOR 34
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 373f068..4ae5565 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1146,6 +1146,18 @@ 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(st->parser->duration,
+                                                         (AVRational){ 1, 
st->codec->sample_rate },
+                                                         st->time_base);
+                        }
+                    } else if (st->codec->time_base.num != 0 &&
+                               st->codec->time_base.den != 0) {
+                        pkt->duration = av_rescale_q(st->parser->duration,
+                                                     st->codec->time_base,
+                                                     st->time_base);
+                    }
                     pkt->stream_index = st->index;
                     pkt->pts = st->parser->pts;
                     pkt->dts = st->parser->dts;
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to