From patchwork Fri Jun 14 16:48:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13535 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 27C054429F8 for ; Fri, 14 Jun 2019 19:57:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0417168A636; Fri, 14 Jun 2019 19:57:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 171F2680223 for ; Fri, 14 Jun 2019 19:57:11 +0300 (EEST) Received: by mail-pl1-f193.google.com with SMTP id bh12so1259092plb.4 for ; Fri, 14 Jun 2019 09:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b7gA4/6vn+xGHarTGxfJy5MwpRIhUJL4RNgPXb2Ra6E=; b=Dw7LfxS9px0tKe8Kz8LxnfiLoinym2XCVO5a4F4cGyuhTz8aY0Z5stmAUEYgntqCoT a0aKopEfvQt2tGYzd/tm19Gy4q8uQCBFJ32fgAGBhHhiNvUpdmH/uFRd/rVwZ4pPmkas 7k3n39+af91GrcoOb+OEukrysoaNz/S9+2FzTngVuugCbjf51B51aY5CbIRAyZ0m1tDV uEOhzb6UlSqtpei20tyeygrFkelv984L3ZNd8bpz2WPBUEmgc6NF7k3qoGmrsEXNRhG0 G1mEe2cyFGP+k7XKd95vqJPMU2T4YWabvaJrHWdAIk2EQuJOsH3Z+P1gad1f4FSyT8Zy 50Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b7gA4/6vn+xGHarTGxfJy5MwpRIhUJL4RNgPXb2Ra6E=; b=BO7k+XECAawfjy2cgkUNKLoYH/PBgySG8tsKWg8OaGbWAdKbUDDNAYZC52DdeMxxcI W4rb65WKwymEaGSHRINcsYVDklD3+nihipx8VeYun5cc1ielOAc2ryMNozXMCwyd6pQO IseDj3VuyAkdPF5SooIS5pWPQSzgYmxbvACFnhgatisxStkQ01fySgFGAtf5p+pKBeQK qmtYkJWtz4kue3B5W88WKLtlJfCDu7+CX1ohot8kDo8J6+5mxjwND9P53TqLYZGqZ122 UGWND9dJtUpN/ESnSVjKaWQRYEzgvYyNx+UzAhoVSIXsukAivHcxhks9hl5p+8EC5cUf zxPg== X-Gm-Message-State: APjAAAVWBtfpH8NXUHC79bbgGO+kUYHvRmg8OP3erm9zKVwzDKpbEiqQ dEUHu45/qPc4mfe/XZ/h1tI13nceDqE= X-Google-Smtp-Source: APXvYqw2I5+nwbzMayLCejLc5l3wx03wmCSlsQOju6guJ+Ns/W36rzFNwx00OTTSG+BnxE1MyXZPCw== X-Received: by 2002:a17:902:28:: with SMTP id 37mr29571766pla.188.1560530928050; Fri, 14 Jun 2019 09:48:48 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id y5sm3183161pgv.12.2019.06.14.09.48.46 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 14 Jun 2019 09:48:47 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jun 2019 00:48:26 +0800 Message-Id: <1560530906-60749-3-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1560530906-60749-1-git-send-email-lance.lmwang@gmail.com> References: <20190612105018.43545-1-lance.lmwang@gmail.com> <1560530906-60749-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v5 3/3] libavfilter/vf_find_rect: convert the object image to gray8 format instead of failed directly X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- doc/filters.texi | 2 +- libavfilter/vf_cover_rect.c | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 4d48068..4594a61 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10180,7 +10180,7 @@ It accepts the following options: @table @option @item cover -Filepath of the optional cover image, needs to be in yuv420. +Filepath of the optional cover image. @item mode Set covering mode. diff --git a/libavfilter/vf_cover_rect.c b/libavfilter/vf_cover_rect.c index b66c40b..502939f 100644 --- a/libavfilter/vf_cover_rect.c +++ b/libavfilter/vf_cover_rect.c @@ -28,6 +28,7 @@ #include "internal.h" #include "lavfutils.h" +#include "lswsutils.h" enum mode { MODE_COVER, @@ -40,6 +41,7 @@ typedef struct CoverContext { int mode; char *cover_filename; AVFrame *cover_frame; + AVFrame *match_frame; int width, height; } CoverContext; @@ -139,8 +141,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) CoverContext *cover = ctx->priv; AVDictionaryEntry *ex, *ey, *ew, *eh; int x = -1, y = -1, w = -1, h = -1; + enum AVPixelFormat in_format; char *xendptr = NULL, *yendptr = NULL, *wendptr = NULL, *hendptr = NULL; AVFrame *cover_frame = NULL; + int ret; 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); @@ -169,14 +173,35 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } w = FFMIN(w, in->width - x); h = FFMIN(h, in->height - y); + in_format = in->format; if (w > in->width || h > in->height || w <= 0 || h <= 0) return AVERROR(EINVAL); if (cover->cover_frame) { - if (w != cover->cover_frame->width || h != cover->cover_frame->height) - return AVERROR(EINVAL); - cover_frame = cover->cover_frame; + if (w != cover->cover_frame->width || h != cover->cover_frame->height || + in_format != cover->cover_frame->format) { + if (!cover->match_frame || (w != cover->match_frame->width || h != cover->match_frame->height + || in_format != cover->match_frame->format)) { + if (cover->match_frame) + av_freep(&cover->match_frame->data[0]); + else if (!(cover->match_frame = av_frame_alloc())) + return AVERROR(ENOMEM); + + if ((ret = ff_scale_image(cover->match_frame->data, cover->match_frame->linesize, + w, h, in_format, cover->cover_frame->data, cover->cover_frame->linesize, + cover->cover_frame->width, cover->cover_frame->height, + cover->cover_frame->format, ctx)) < 0) + return AVERROR(ENOMEM); + + cover->match_frame->width = w; + cover->match_frame->height = h; + cover->match_frame->format = in_format; + } + + cover_frame = cover->match_frame; + } else + cover_frame = cover->cover_frame; } cover->width = w; @@ -202,6 +227,10 @@ static av_cold void uninit(AVFilterContext *ctx) if (cover->cover_frame) av_freep(&cover->cover_frame->data[0]); av_frame_free(&cover->cover_frame); + + if (cover->match_frame) + av_freep(&cover->match_frame->data[0]); + av_frame_free(&cover->match_frame); } static av_cold int init(AVFilterContext *ctx) @@ -223,11 +252,6 @@ static av_cold int init(AVFilterContext *ctx) &cover->cover_frame->width, &cover->cover_frame->height, &cover->cover_frame->format, cover->cover_filename, ctx)) < 0) return ret; - - if (cover->cover_frame->format != AV_PIX_FMT_YUV420P && cover->cover_frame->format != AV_PIX_FMT_YUVJ420P) { - av_log(ctx, AV_LOG_ERROR, "cover image is not a YUV420 image\n"); - return AVERROR(EINVAL); - } } return 0;