From patchwork Tue Jun 11 12:42:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jb X-Patchwork-Id: 13500 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 5467B449325 for ; Tue, 11 Jun 2019 15:43:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D3D7680BCE; Tue, 11 Jun 2019 15:43:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A377680446 for ; Tue, 11 Jun 2019 15:42:58 +0300 (EEST) Received: by mail-wr1-f48.google.com with SMTP id m3so12891780wrv.2 for ; Tue, 11 Jun 2019 05:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=oADxgJMU4bXNH4ygD/7G2/xA1usUtlFwy6A06uSoPHU=; b=p5LjD9FwZBayEbYzwrqh6E6bZ5OOBq5l33Fmsh5EmUs0LjwYr792gdHAN8lmsS9BzY YOpBgLKgmkkUA4kLYI5fR+YCTFt8/t2DvqkWOvoVnLAS6PvTbFGbHnPYS8aeXVbvKUFl rNPe/YUkrllDzZENQ+PAG/7XKKYXRWq8uorO82t6Onghf2EtQyuovAJsITQvS6phkWF2 tX7MHVmKCRVgGNngYHA9zKCX6USdZXM9VVHKfj/K8MDqEzJGn22A095oaDnRZrnOrbvM V5BF00FzRJqW5y1eeFIhGkA0cTZsoIOBcJqTmjNJzx688N2JZNOEnpAs6OsOjHKp6tD1 rTuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=oADxgJMU4bXNH4ygD/7G2/xA1usUtlFwy6A06uSoPHU=; b=l8pSywu9rX+N5eJyJew89Tat0Y/G8AXPaHWtM/8vx3GJZsr5T1PTaWjBsbi6ZuOmkA idFOYK4+/7AhkbPbODwFWygDHj9FfybN3aGkBEir2JNIH4AMUFND3Ny8/TuO/uxw5pRs hTMbc/h6GOhlI+CDwpSCo6kMTPUS4eJf9f2c3Rrga3pSep2/7vbgK7Zw8862daEYFYnL zlE2CF0y+TlvDp0zn+5HtFkxJasxlmSsUkzmq3bse6rj2dF2d9w0F6VhjQVNo39NbjSn OBiXbC2yKeKtynzWVAM3kdlVqVTpVu3Bq0cuoeKyYgoRmOQjTk2rVtiBfztzZIyWSrt1 HmEA== X-Gm-Message-State: APjAAAXmvQPTwBfXtQ3Xe6uGfj1Ihv6Ae/1TObPPDTiCc1vyhns7/21P WtCzAJxAbGjiJ4xYSzmGM0pp6GSQ X-Google-Smtp-Source: APXvYqx66RI6gKy+L/y6ClGIfYkqf+cwqxZBExWihSN3aacqlsDmGUj66iZzHDy6r95rcYJ/z2kMMQ== X-Received: by 2002:adf:ead1:: with SMTP id o17mr4899930wrn.176.1560256977478; Tue, 11 Jun 2019 05:42:57 -0700 (PDT) Received: from jonathan-imac.discovery.intern ([188.194.249.113]) by smtp.gmail.com with ESMTPSA id y17sm29536624wrg.18.2019.06.11.05.42.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 05:42:56 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org From: Jonathan Baecker Message-ID: Date: Tue, 11 Jun 2019 14:42:55 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [Patch v2] drawtext: ignore last newline 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is a new version from my last patch. As Gyan suggested it is now optional to skip/trim the last line break. From 8d31aab97ceaaec4947e1628e2ff1391dd77d4b2 Mon Sep 17 00:00:00 2001 From: Jonathan Baecker Date: Tue, 11 Jun 2019 14:33:50 +0200 Subject: [PATCH] trim last empty line --- libavfilter/vf_drawtext.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- 2.21.0 diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 01cd7fa12..22ec870ed 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -139,7 +139,7 @@ typedef struct DrawTextContext { int exp_mode; ///< expansion mode to use for the text int reinit; ///< tells if the filter is being reinited #if CONFIG_LIBFONTCONFIG - uint8_t *font; ///< font to be used + uint8_t *font; ///< font to be used #endif uint8_t *fontfile; ///< font to be used uint8_t *text; ///< text to be drawn @@ -162,6 +162,7 @@ typedef struct DrawTextContext { unsigned int default_fontsize; ///< default font size to use int line_spacing; ///< lines spacing in pixels + int trim_end; ///< skip last empty line - true/false short int draw_box; ///< draw box around text - true or false int boxborderw; ///< box border width int use_kerning; ///< font kerning is used - true/false @@ -211,6 +212,7 @@ static const AVOption drawtext_options[]= { {"boxcolor", "set box color", OFFSET(boxcolor.rgba), AV_OPT_TYPE_COLOR, {.str="white"}, CHAR_MIN, CHAR_MAX, FLAGS}, {"bordercolor", "set border color", OFFSET(bordercolor.rgba), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS}, {"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS}, + {"trim_end", "trim last empty line", OFFSET(trim_end), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS}, {"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS}, {"boxborderw", "set box border width", OFFSET(boxborderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS}, {"line_spacing", "set line spacing in pixels", OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX,FLAGS}, @@ -1377,6 +1379,18 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, /* compute and save position for each glyph */ glyph = NULL; + + if (s->trim_end) { + /* skip last newline character */ + char * last = text + len - 1; + char * second_last = text + len - 2; + + if (*second_last == '\r' && *last == '\n') + *second_last = 0; + else if (*last == '\r' || *last == '\n') + *last = 0; + } + for (i = 0, p = text; *p; i++) { GET_UTF8(code, *p++, continue;);