From: Stefano Sabatini <[email protected]>

The format is a per-frame property, having it in AVFrame simplify the
operation of extraction of that information, since avoids the need to
access the codec/stream context.
---
 libavcodec/avcodec.h |    9 +++++++++
 libavcodec/utils.c   |    5 +++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 9cee89d..fdcd844 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1272,6 +1272,15 @@ typedef struct AVFrame {
      * - decoding: Read by user.
      */
     int width, height;
+
+    /**
+     * format of the frame, -1 if unknown or unset
+     * It should be cast to the corresponding enum (enum PixelFormat
+     * for video, enum AVSampleFormat for audio)
+     * - encoding: unused
+     * - decoding: Read by user.
+     */
+    int format;
 } AVFrame;
 
 struct AVCodecInternal;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 27e1a6b..5fa9ca6 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -585,6 +585,7 @@ void avcodec_get_frame_defaults(AVFrame *pic){
     pic->pts= AV_NOPTS_VALUE;
     pic->key_frame= 1;
     pic->sample_aspect_ratio = (AVRational){0, 1};
+    pic->format = -1;           /* unknown */
 }
 
 AVFrame *avcodec_alloc_frame(void){
@@ -865,6 +866,8 @@ int attribute_align_arg 
avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
                 picture->width = avctx->width;
             if (!picture->height)
                 picture->height = avctx->height;
+            if (picture->format == PIX_FMT_NONE)
+                picture->format = avctx->pix_fmt;
         }
 
         emms_c(); //needed to avoid an emms_c() call before every return;
@@ -986,6 +989,8 @@ int attribute_align_arg 
avcodec_decode_audio4(AVCodecContext *avctx,
         if (ret >= 0 && *got_frame_ptr) {
             avctx->frame_number++;
             frame->pkt_dts = avpkt->dts;
+            if (frame->format == AV_SAMPLE_FMT_NONE)
+                frame->format = avctx->sample_fmt;
         }
     }
     return ret;
-- 
1.7.7.3

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

Reply via email to