[FFmpeg-devel] [PATCH] lavc: add width and height fields to AVFrame

Stefano Sabatini stefano.sabatini-lala at poste.it
Sun May 1 15:56:20 CEST 2011


width and height are per-frame properties, setting that value in
AVFrame simplify the operation of extraction of that information,
since there is no need to check the codec/stream context.
---
 libavcodec/avcodec.h      |    7 +++++++
 libavcodec/utils.c        |    4 ++++
 libavfilter/vsrc_buffer.c |    2 ++
 3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3f8f1a6..9d30a59 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1018,6 +1018,13 @@ typedef struct AVPanScan{
      * - decoding: Read by user.\
      */\
     AVRational sample_aspect_ratio;\
+\
+    /**\
+     * width and height of the video frame\
+     * - encoding: unused\
+     * - decoding: Read by user.\
+     */\
+    int width, height;\
 
 
 #define FF_QSCALE_TYPE_MPEG1 0
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 5977d3c..53eedd6 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -740,6 +740,10 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
             picture->pkt_pos= avpkt->pos;
             if (!picture->sample_aspect_ratio.num)
                 picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
+            if (!picture->width)
+                picture->width = avctx->width;
+            if (!picture->height)
+                picture->height = avctx->height;
         }
 
         emms_c(); //needed to avoid an emms_c() call before every return;
diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c
index 906cb5d..8c0073f 100644
--- a/libavfilter/vsrc_buffer.c
+++ b/libavfilter/vsrc_buffer.c
@@ -100,6 +100,8 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame,
 
     memcpy(c->frame.data    , frame->data    , sizeof(frame->data));
     memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
+    c->frame.width  = frame->width;
+    c->frame.height = frame->height;
     c->frame.interlaced_frame= frame->interlaced_frame;
     c->frame.top_field_first = frame->top_field_first;
     c->frame.key_frame = frame->key_frame;
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list