From patchwork Mon Feb 19 21:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oneric X-Patchwork-Id: 46370 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp1510821pzb; Mon, 19 Feb 2024 13:43:17 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVYdSEQN6qxc4mRsb4RtDXz3UxmnAepIuB12QC5XyUXEsXeYizll8y/rk/q1+rfxXum2ZG/Bm/GLI21uvtVXUwF7H7TO6lqhHcWAQ== X-Google-Smtp-Source: AGHT+IEM9RnFTbLW/OiJIqQSI/1LK25InR9aQKhsOE8alytfM4oFyNZDpgMQmeS+SiV0G6Q9RfYb X-Received: by 2002:a50:d711:0:b0:564:9fe1:4f60 with SMTP id t17-20020a50d711000000b005649fe14f60mr1693643edi.0.1708378997107; Mon, 19 Feb 2024 13:43:17 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i38-20020a0564020f2600b005642f0a0ba0si2335688eda.441.2024.02.19.13.43.16; Mon, 19 Feb 2024 13:43:17 -0800 (PST) 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=@oneric.de header.s=strato-dkim-0002 header.b=jRgUr0aZ; dkim=neutral (no key) header.i=@oneric.de header.s=strato-dkim-0003; arc=fail (body hash mismatch); 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CF5D68D41A; Mon, 19 Feb 2024 23:42:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.160]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0451C68D3F7 for ; Mon, 19 Feb 2024 23:42:41 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; t=1708378961; cv=none; d=strato.com; s=strato-dkim-0002; b=ozfbjYQ9sfgPEJea9mSwd5V9EtbNlgu+HEHPCOU+SXZAW2n4xcYgzJWM24cOPL0DN8 uSeajtFnI/spqLomxMyQeZaAKjamAwnPrjVHEsuZkg/L45VmzkIzMOUKNBx5fPtW/L/G 5hmrzZs+PQd8frgxscx9tUX8vLHTNlaLz3M1q6O+2iqYw88GmiYyeMgr4fT6pIMIsEHr QOxpyUrh6tg7fI5alkRxonOuGN/aKbZvqrae5/KHgDbBl1p9K8VipWEOllc6mQpNVeIN APF/6LdwpVIm7pegNcz/prlofwnirNPLPniFR7VAphLLVF62b3JaedLHBQtaNCgDwAA/ B6GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1708378961; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=sWhLf975+n9pDZ+kqOvmCzNKzKIN8af5zcf5+xAzACU=; b=qejOm3c/Uotqd+CkQnUjl8pyUyEPQCdcfXuoEAjO9cA1vmokLTOfWLz/7VfoIevNHA OqhopFn26QMAGAsRWf8Ko6LNPBFrrq0Ck4baFLkhoyPn6K7bsuA+D9fN13poL6qXuv5S DnFjusY2j/vAi3VMVi/xBFndv0OICd3Nf7vx97m0oC0JGgwapvbQ+8opfGonLHtC6XW2 9W9rTjRg/x5qfvzbIVlwE3gAiqB2inzPdrgmJOhr3uNC8Y7S+u2ApPWt4v3bKEBbrQ7Y qSHZnzFlbuwzsnH5o4AuBlzqLhibRuX2tsvAEES/WFgNBRZk+FbMeLvHdFRrEMkiGQTP TUMw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1708378961; s=strato-dkim-0002; d=oneric.de; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=sWhLf975+n9pDZ+kqOvmCzNKzKIN8af5zcf5+xAzACU=; b=jRgUr0aZKcl5aNqYDOJs/WdrkDyKpRFNoY/X6IEjvo8SpQ6cfvxlTy66qvkjEmID6L 9lslDFDYKdgAkYGGuWJ8uUrbr96RD2zbs2mSHZi5832IShfXnmHmZexFK06UBB7/ypZz NUGQOTYhvt84Jm/bmCHOykezqRg5M3tijwVAgG+0Fmr/+1CYL2ucOgq/Wk31YytAVMcG kaLVqjE07mxTDpoNIuJjVCxzzA2Wr2beWCC797snhjlZaZYsnx9LUf/NfDmnZkFaj6be LP3pfZBXJRT6fTVBcygdGVasTlwzd17biFu9vsluJ3YCTUHnnPcZPQnBDQqMjQJt02ta 5sOg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1708378961; s=strato-dkim-0003; d=oneric.de; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Cc:Date:From: Subject:Sender; bh=sWhLf975+n9pDZ+kqOvmCzNKzKIN8af5zcf5+xAzACU=; b=LvI1aDYk1tidtHcRuZMP+BViSecc1ohBpgszHzTCSh8nkLlNK5wKpikpZx73Dsn7Kt t5STPoEtdlLLLdSwUmBg== X-RZG-AUTH: ":I2IBZ0mrW/AWQXwgB4oxKM1YsW1lFUznrLvi/XReWqAAlWwZ8wlvfXmGs4jUQ0oz8ZbhHexs8fhgUyUBddsh74Htfavbxf07Su2y8qQ=" Received: from abhoth.workgroup by smtp.strato.de (RZmta 49.11.2 AUTH) with ESMTPSA id x7ec2e01JLgfXQn (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Mon, 19 Feb 2024 22:42:41 +0100 (CET) From: Oneric To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Feb 2024 22:42:26 +0100 Message-Id: <20240219214227.19814-4-oneric@oneric.de> In-Reply-To: <20240219214227.19814-1-oneric@oneric.de> References: <20240219214227.19814-1-oneric@oneric.de> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/4] avcodec/{ass, webvttdec}: more portable curly brace escapes 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: g04RES9yvEtH Unlike what the old comment suggested, standard ASS has no character escape mechanism, but a closing curly bracket doesn't even need one. For manual authored sub files using a full-width variant of an apropiate font and with scaling and psacing modifiers is a common workaround. This is not an option here, but we can still make things much less bad. Now the desired opening bracket still shows up in libass and standard renders will merely display a backslash in its place instead of stripping the following text like before. --- libavcodec/ass.c | 12 ++++++++---- libavcodec/webvttdec.c | 2 +- tests/ref/fate/sub-webvtt | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/ass.c b/libavcodec/ass.c index a68d3568b4..e7a1ac0eb5 100644 --- a/libavcodec/ass.c +++ b/libavcodec/ass.c @@ -181,10 +181,14 @@ void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size, if (linebreaks && strchr(linebreaks, *p)) { av_bprintf(buf, "\\N"); - /* standard ASS escaping so random characters don't get mis-interpreted - * as ASS */ - } else if (!keep_ass_markup && strchr("{}", *p)) { - av_bprintf(buf, "\\%c", *p); + /* cancel curly brackets to avoid bogus override tag blocks + * hiding text. Standard ASS has no character escapes, + * though (only) libass provides \{ and \}. + * Unpaired closing brackets don't need escaping at all though and + * to make the situation less bad in standard ASS insert an empty block + */ + } else if (!keep_ass_markup && *p == '{') { + av_bprintf(buf, "\\{{}"); /* append word-joiner U+2060 as UTF-8 to break up sequences like \N */ } else if (!keep_ass_markup && *p == '\\') { diff --git a/libavcodec/webvttdec.c b/libavcodec/webvttdec.c index 6e55bc5499..35bdbe805d 100644 --- a/libavcodec/webvttdec.c +++ b/libavcodec/webvttdec.c @@ -37,7 +37,7 @@ static const struct { {"", "{\\i1}"}, {"", "{\\i0}"}, {"", "{\\b1}"}, {"", "{\\b0}"}, {"", "{\\u1}"}, {"", "{\\u0}"}, - {"{", "\\{"}, {"}", "\\}"}, {"\\", "\\\xe2\x81\xa0"}, // escape to avoid ASS markup conflicts + {"{", "\\{{}"}, {"\\", "\\\xe2\x81\xa0"}, // escape to avoid ASS markup conflicts {">", ">"}, {"<", "<"}, {"‎", "\xe2\x80\x8e"}, {"‏", "\xe2\x80\x8f"}, {"&", "&"}, {" ", "\\h"}, diff --git a/tests/ref/fate/sub-webvtt b/tests/ref/fate/sub-webvtt index ea587b327c..fae50607fb 100644 --- a/tests/ref/fate/sub-webvtt +++ b/tests/ref/fate/sub-webvtt @@ -21,7 +21,7 @@ Dialogue: 0,0:00:22.00,0:00:24.00,Default,,0,0,0,,at the AMNH. Dialogue: 0,0:00:24.00,0:00:26.00,Default,,0,0,0,,Thank you for walking down here. Dialogue: 0,0:00:27.00,0:00:30.00,Default,,0,0,0,,And I want to do a follow-up on the last conversation we did.\Nmultiple lines\Nagain Dialogue: 0,0:00:30.00,0:00:31.50,Default,,0,0,0,,When we e-mailed— -Dialogue: 0,0:00:30.50,0:00:32.50,Default,,0,0,0,,Didn't we {\b1}talk {\i1}about\N{\i0} enough{\b0} in that conversation? \{I'm not an ASS comment\} +Dialogue: 0,0:00:30.50,0:00:32.50,Default,,0,0,0,,Didn't we {\b1}talk {\i1}about\N{\i0} enough{\b0} in that conversation? \{{}I'm not an ASS comment} Dialogue: 0,0:00:32.00,0:00:35.50,Default,,0,0,0,,No! No no no no; 'cos 'cos obviously 'cos Dialogue: 0,0:00:32.50,0:00:33.50,Default,,0,0,0,,{\i1}Laughs{\i0} Dialogue: 0,0:00:35.50,0:00:38.00,Default,,0,0,0,,You know I'm so excited my glasses are falling off here.