[FFmpeg-cvslog] mpegvideo: allocate edges when encoding.

Anton Khirnov git at videolan.org
Mon Jan 20 17:15:44 CET 2014


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Jan  1 20:04:53 2014 +0100| [024db24912a39316b0ef0b7d793307d62da038f4] | committer: Anton Khirnov

mpegvideo: allocate edges when encoding.

Allocating edges will be removed from generic code, so the encoder must
handle this explicitly.

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

 libavcodec/mpegvideo.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 6ecfd72..a80f737 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -422,15 +422,21 @@ fail:
  */
 static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
 {
+    int edges_needed = av_codec_is_encoder(s->avctx->codec);
     int r, ret;
 
     pic->tf.f = &pic->f;
     if (s->codec_id != AV_CODEC_ID_WMV3IMAGE &&
         s->codec_id != AV_CODEC_ID_VC1IMAGE  &&
-        s->codec_id != AV_CODEC_ID_MSS2)
+        s->codec_id != AV_CODEC_ID_MSS2) {
+        if (edges_needed) {
+            pic->f.width  = s->avctx->width  + 2 * EDGE_WIDTH;
+            pic->f.height = s->avctx->height + 2 * EDGE_WIDTH;
+        }
+
         r = ff_thread_get_buffer(s->avctx, &pic->tf,
                                  pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
-    else {
+    } else {
         pic->f.width  = s->avctx->width;
         pic->f.height = s->avctx->height;
         pic->f.format = s->avctx->pix_fmt;
@@ -443,6 +449,18 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
         return -1;
     }
 
+    if (edges_needed) {
+        int i;
+        for (i = 0; pic->f.data[i]; i++) {
+            int offset = (EDGE_WIDTH >> (i ? s->chroma_y_shift : 0)) *
+                         pic->f.linesize[i] +
+                         (EDGE_WIDTH >> (i ? s->chroma_x_shift : 0));
+            pic->f.data[i] += offset;
+        }
+        pic->f.width  = s->avctx->width;
+        pic->f.height = s->avctx->height;
+    }
+
     if (s->avctx->hwaccel) {
         assert(!pic->hwaccel_picture_private);
         if (s->avctx->hwaccel->priv_data_size) {



More information about the ffmpeg-cvslog mailing list