[FFmpeg-devel] [PATCH v5 2/3] ibavfilter/vf_cover_rect.c: change the cover_rect function for support cover frame can be changed

lance.lmwang at gmail.com lance.lmwang at gmail.com
Fri Jun 14 19:48:25 EEST 2019


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavfilter/vf_cover_rect.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_cover_rect.c b/libavfilter/vf_cover_rect.c
index 898debf..b66c40b 100644
--- a/libavfilter/vf_cover_rect.c
+++ b/libavfilter/vf_cover_rect.c
@@ -71,24 +71,25 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void cover_rect(CoverContext *cover, AVFrame *in, int offx, int offy)
+static void cover_rect(AVFrame *cover_frame, AVFrame *in, int offx, int offy)
 {
     int x, y, p;
 
     for (p = 0; p < 3; p++) {
         uint8_t *data = in->data[p] + (offx>>!!p) + (offy>>!!p) * in->linesize[p];
-        const uint8_t *src = cover->cover_frame->data[p];
-        int w = AV_CEIL_RSHIFT(cover->cover_frame->width , !!p);
-        int h = AV_CEIL_RSHIFT(cover->cover_frame->height, !!p);
+        const uint8_t *src = cover_frame->data[p];
+        int w = AV_CEIL_RSHIFT(cover_frame->width , !!p);
+        int h = AV_CEIL_RSHIFT(cover_frame->height, !!p);
         for (y = 0; y < h; y++) {
             for (x = 0; x < w; x++) {
                 data[x] = src[x];
             }
             data += in->linesize[p];
-            src += cover->cover_frame->linesize[p];
+            src += cover_frame->linesize[p];
         }
     }
 }
+
 static void blur(CoverContext *cover, AVFrame *in, int offx, int offy)
 {
     int x, y, p;
@@ -139,6 +140,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVDictionaryEntry *ex, *ey, *ew, *eh;
     int x = -1, y = -1, w = -1, h = -1;
     char *xendptr = NULL, *yendptr = NULL, *wendptr = NULL, *hendptr = NULL;
+    AVFrame *cover_frame = NULL;
 
     ex = av_dict_get(in->metadata, "lavfi.rect.x", NULL, AV_DICT_MATCH_CASE);
     ey = av_dict_get(in->metadata, "lavfi.rect.y", NULL, AV_DICT_MATCH_CASE);
@@ -174,6 +176,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     if (cover->cover_frame) {
         if (w != cover->cover_frame->width || h != cover->cover_frame->height)
             return AVERROR(EINVAL);
+        cover_frame = cover->cover_frame;
     }
 
     cover->width  = w;
@@ -186,8 +189,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     if (cover->mode == MODE_BLUR) {
         blur (cover, in, x, y);
-    } else {
-        cover_rect(cover, in, x, y);
+    } else if (cover_frame) {
+        cover_rect(cover_frame, in, x, y);
     }
     return ff_filter_frame(ctx->outputs[0], in);
 }
-- 
2.6.4



More information about the ffmpeg-devel mailing list