From patchwork Mon Apr 26 09:34:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 27419 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp3807289iob; Mon, 26 Apr 2021 02:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuhVHxZr3ta6t7khNEYo9Z+kTpnFNH9MSceaDBl1qCRpUGPIasnK/KrVQM8pM5vFvJpwBZ X-Received: by 2002:a17:906:1101:: with SMTP id h1mr18107029eja.179.1619430106430; Mon, 26 Apr 2021 02:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619430106; cv=none; d=google.com; s=arc-20160816; b=MK92+YPRe9POG5ZRQBaOximQQS/Lka6lGAh48csvcFj/g+mVv8Aj74gJLSqnILH6Fz vqgS8Ol3PTF32pTTxu1S/lHT63ZNBMnEzXMpfnb27xQIHTIBqptGqiHVoqP2hXWHGZkc +j8u1SX4334Z1d+9sYngQ+3oiBMHIygGo1NZGG+FVvBngg8M57miwVv2wfXK43/C1fN3 KSl1Xe9L840xu7RcjDPVz0M07b4VWdxpLEN0UZp3Sq0G+UAnKsSIZWCWQEbMYF5l6XpL NJWzdBhruvyJNfe5kuxdjr6Ks1vNzgPkuxrNeqgZBw9oOQcBanbB0bE8DlxBhoPnJajO rUSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=78uLzKqGGaNeQjSmnV0SpX+paAOrqamnvorQF/16jnQ=; b=GkCrDATHSFxdQqY7d28wW1tI28zcRxgdTuZ0bmpEwztY59bMFSwjY1PeVNDyhJyToI ueGVIPLB90rYewCjvBf6PuGbdQOyfy6EEEtkRYLGofRlbr7rGel6fz62xyI34w7MxQoq znqOpMkdVCrqykLq2qTiYLSXkFz3zwaM3W+Bh5vd1zPFTKqdzQpPCFnovf8393T9FoU7 fbLpcfGNii30u3u1cxUPwiFYbQlLNcHFLrQjBsrjbST7D8vfpMn0uDzRwKOCEMWijfwb pzNB59OqOkDD5v7SgaXw7USdbmYtz7ahFJe6owGhcz9nq7MK+6GRA85maK81ZE34PtnL Ut4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NkJw6cO9; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v17si12835916edr.447.2021.04.26.02.41.46; Mon, 26 Apr 2021 02:41:46 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NkJw6cO9; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B52B4689A6F; Mon, 26 Apr 2021 12:41:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7F56F680836 for ; Mon, 26 Apr 2021 12:41:37 +0300 (EEST) Received: by mail-ej1-f41.google.com with SMTP id r9so83459699ejj.3 for ; Mon, 26 Apr 2021 02:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pJUgGSoVQfL7FX41APYMAE5h7AYq6pxduKYv8eTH0Do=; b=NkJw6cO9GADIQ4DGvpuO10OlG1EMhXzCOMSP+8PPOZecMw0CJKFBFr6BxireBGy2UB UdqHBc+d1t3jrt2oNgJE3P4vzcFiqOQ51FmwgXpJ1cSAwA8MSY0nF+AOX+s3KoT1rO8n 73RFJQTa292v1RIK1VDAMg0uyoW/+FJl7+8HQSvuyOng84MX6BSyz2qe9IYc2V8Z2Xhj PlPyOcg2qeBecZWt/Rao9dwDV7fiojMG6Dau2uLF6b8vmmRL8effahLU+ip2bJYZ7yZ/ BsoOWuaE4sDcdTVGtFxvlK5jBllfRPhihduMoPjX9czuDppmLumBsqZELBR68MtYee5y cN3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pJUgGSoVQfL7FX41APYMAE5h7AYq6pxduKYv8eTH0Do=; b=gmf1t0jVxC0A/2mjDHh9zPmz6pmHVdR4jaegKpCSExPO+LVkhqp5vl7Xd4xfktB5l9 OWlNy1PV1IsxGsG77C9O5LqCY7TSNjiTwr+cjzakdMiLEqmr6ml+qnwukZVWbabDMWS3 CIybvse66uV6UgXyY9M5a9KHzmiXW938e74/PNKmBsqOXm6A+oa593xgN3nrR/1Bb4ML bbX06Q1ZMBxx4IN+9h3deIHcBxELaX+gjLx+5Pg20D9I+3y1qb0TfTkcYODnyxCvOKsB pRFKp+SZoKYhean324FmUcPFnPJkqt5BtCm7ljtuLybYr7B2KIVeNtcuy0by0cIBMIvZ ujCg== X-Gm-Message-State: AOAM532x9+9f8qcW2hOSX2VaQ01A8VuaV7BevH/bJODUhI174JN9soEX Osv7uMPfH7hms35NjPYCWjV2ozOtIWo= X-Received: by 2002:ac2:4f86:: with SMTP id z6mr12343181lfs.156.1619429671655; Mon, 26 Apr 2021 02:34:31 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id m7sm1402883ljp.102.2021.04.26.02.34.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 02:34:31 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Apr 2021 12:34:25 +0300 Message-Id: <20210426093425.17900-5-jeebjp@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210426093425.17900-1-jeebjp@gmail.com> References: <20210426093425.17900-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 4/4] avcodec/ttmlenc: add support for region positioning and sizing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: iTsvEVU6b8R0 From: Jan Ekström The ASS margins are utilized to generate percentual values, as the usage of cell-based sizing and offsetting seems to be not too well supported by renderers. Signed-off-by: Jan Ekström --- libavcodec/ttmlenc.c | 45 ++++++++++++++++++++++++++++++++++++-- tests/ref/fate/sub-ttmlenc | 2 ++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c index 37372b29cd..6dfcc0a216 100644 --- a/libavcodec/ttmlenc.c +++ b/libavcodec/ttmlenc.c @@ -237,11 +237,35 @@ static const char *ttml_get_text_alignment(int alignment) } } +static void ttml_get_origin(ASSScriptInfo script_info, ASSStyle style, + int *origin_left, int *origin_top) +{ + *origin_left = av_rescale(style.margin_l, 100, script_info.play_res_x); + *origin_top = + av_rescale((style.alignment >= 7) ? style.margin_v : 0, + 100, script_info.play_res_y); +} + +static void ttml_get_extent(ASSScriptInfo script_info, ASSStyle style, + int *width, int *height) +{ + *width = av_rescale(script_info.play_res_x - style.margin_r, + 100, script_info.play_res_x); + *height = av_rescale((style.alignment <= 3) ? + script_info.play_res_y - style.margin_v : + script_info.play_res_y, + 100, script_info.play_res_y); +} + static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf, - ASSStyle style) + ASSScriptInfo script_info, ASSStyle style) { const char *display_alignment = NULL; const char *text_alignment = NULL; + int origin_left = 0; + int origin_top = 0; + int width = 0; + int height = 0; if (!style.name) { av_log(avctx, AV_LOG_ERROR, "Subtitle style name not set!\n"); @@ -254,6 +278,14 @@ static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf, return AVERROR_INVALIDDATA; } + if (style.margin_l < 0 || style.margin_r < 0 || style.margin_v < 0) { + av_log(avctx, AV_LOG_ERROR, + "One or more negative margin values in subtitle style: " + "left: %d, right: %d, vertical: %d!\n", + style.margin_l, style.margin_r, style.margin_v); + return AVERROR_INVALIDDATA; + } + display_alignment = ttml_get_display_alignment(style.alignment); text_alignment = ttml_get_text_alignment(style.alignment); if (!display_alignment || !text_alignment) { @@ -265,11 +297,19 @@ static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf, return AVERROR_INVALIDDATA; } + ttml_get_origin(script_info, style, &origin_left, &origin_top); + ttml_get_extent(script_info, style, &width, &height); + av_bprintf(buf, " buffer, " \n"); for (int i = 0; i < ass->styles_count; i++) { - int ret = ttml_write_region(avctx, &s->buffer, ass->styles[i]); + int ret = ttml_write_region(avctx, &s->buffer, script_info, + ass->styles[i]); if (ret < 0) return ret; } diff --git a/tests/ref/fate/sub-ttmlenc b/tests/ref/fate/sub-ttmlenc index 6d0a8067fc..4df8f8796f 100644 --- a/tests/ref/fate/sub-ttmlenc +++ b/tests/ref/fate/sub-ttmlenc @@ -9,6 +9,8 @@