From patchwork Sat Sep 10 08:45:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 524 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp694326vsd; Sat, 10 Sep 2016 01:45:56 -0700 (PDT) X-Received: by 10.194.184.39 with SMTP id er7mr6707464wjc.159.1473497156388; Sat, 10 Sep 2016 01:45:56 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t129si4691138wme.25.2016.09.10.01.45.55; Sat, 10 Sep 2016 01:45:56 -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; 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 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 3F97E689E70; Sat, 10 Sep 2016 11:45:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f68.google.com (mail-oi0-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 22537689CDE for ; Sat, 10 Sep 2016 11:45:24 +0300 (EEST) Received: by mail-oi0-f68.google.com with SMTP id 2so13866412oif.2 for ; Sat, 10 Sep 2016 01:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=bnOBbnWRIFFuo3h/cSIiSrzsTACcQubrTrPZH86rF5k=; b=qWLeHPraVx57emfThwxISdXtKsNE1q6sdAA7rZraUNRed6jfG1oqDP9I0gLuXf6VIi Wx/QMfDwdVz2EKXSvEY/Q1x1agshokE31yZ0I9yrN2RpZNPwLubkuaWPu5JN/L4isZa/ VdhBb7ZELi0ks5vjLnW3AWQgMYzyjaBVc9x6fh56y/FXFDFbgoXBNfAP90Is410tNQVK KQ2SErDOWBZZz+mL34dY9Y/xzdaEnFAMIC26hor/yjtPO1OCnX7y4zijPikzsu81c50Y eMXzZq+9CbFBYfaXcv5gKOy5d1ng0wFZJyHJNe4UWombuHQAK7Wd3KYlTtbSsUfQ2tkD FKzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=bnOBbnWRIFFuo3h/cSIiSrzsTACcQubrTrPZH86rF5k=; b=ftSiqia+rbNjwV9vhJNtFLdpnXy0WfdKkP7OO26jIIKGeqaHmvTOW/rSYe2eOC/oTn Jnjkl2gSFTw78bqBnZUg3/c7DNGQPuM/4OnXwMHXDauHVpbiLMfXnSpnNYgB6g9Xzq04 GrCVeaJlWDGayOPrkykjeOIG8WBJq41jl1JeoAewqcp0T0VDOwKgXKswrVKiVHAxWz1u zm6d3MWaBTcxwQw/vZMxmNc6JRjehwxNVC5EBEclXVrfsven38q5bY3vRyZcJ3W4Irbs WrFh0w8vpHHhwYXy60XazJzNsC+N750aK0Dhmxrt2uPNcjPCAru9H1BbjnG7mGlKFWfe hRww== X-Gm-Message-State: AE9vXwOwudI+FnVZSTQGt/Z8NhOCHv9zexyZtfUgR5VTcU3GzS8Y781yOJTKpEAOOE4OBg== X-Received: by 10.157.63.33 with SMTP id m30mr11448394otc.156.1473497134617; Sat, 10 Sep 2016 01:45:34 -0700 (PDT) Received: from Rodgers-MacBook-Pro.local.net (c-73-209-137-129.hsd1.il.comcast.net. [73.209.137.129]) by smtp.gmail.com with ESMTPSA id z73sm3191071ita.16.2016.09.10.01.45.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 10 Sep 2016 01:45:34 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Sep 2016 03:45:31 -0500 Message-Id: <20160910084531.11103-1-rodger.combs@gmail.com> X-Mailer: git-send-email 2.10.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/ass_split: improve handling of complex ASS features 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" Specifically: - Skip writing drawings as text - Convert \h to a Unicode non-breaking space - Ignore comments and unknown tags The test references are update to reflect these changes. --- libavcodec/ass_split.c | 29 +++++++++++++++++------------ tests/ref/fate/sub-textenc | 12 ++++++------ tests/ref/fate/sub-webvttenc | 12 ++++++------ 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index beaba7e..b25a0f3 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -477,30 +477,37 @@ int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *text = NULL; char new_line[2]; int text_len = 0; + int drawing = 0; while (buf && *buf) { if (text && callbacks->text && - (sscanf(buf, "\\%1[nN]", new_line) == 1 || - !strncmp(buf, "{\\", 2))) { - callbacks->text(priv, text, text_len); + (sscanf(buf, "\\%1[nNh]", new_line) == 1 || + *buf == '{')) { + if (!drawing) + callbacks->text(priv, text, text_len); text = NULL; } - if (sscanf(buf, "\\%1[nN]", new_line) == 1) { + if (buf[0] == '\\' && buf[1] == 'h') { + callbacks->text(priv, "\u00A0", 2); + buf += 2; + } else if (sscanf(buf, "\\%1[nN]", new_line) == 1) { if (callbacks->new_line) callbacks->new_line(priv, new_line[0] == 'N'); buf += 2; - } else if (!strncmp(buf, "{\\", 2)) { - buf++; + } else if (*buf == '{' && strchr(buf, '}')) { + buf += strcspn(buf, "\\}"); // skip comments while (*buf == '\\') { char style[2], c[2], sep[2], c_num[2] = "0", tmp[128] = {0}; unsigned int color = 0xFFFFFFFF; - int len, size = -1, an = -1, alpha = -1; + int len = 2, size = -1, an = -1, alpha = -1; int x1, y1, x2, y2, t1 = -1, t2 = -1; if (sscanf(buf, "\\%1[bisu]%1[01\\}]%n", style, c, &len) > 1) { int close = c[0] == '0' ? 1 : c[0] == '1' ? 0 : -1; len += close != -1; if (callbacks->style) callbacks->style(priv, style[0], close); + } else if (sscanf(buf, "\\p%u%1[\\}]%n", &size, sep, &len) > 1) { + drawing = (size > 0); } else if (sscanf(buf, "\\c%1[\\}]%n", sep, &len) > 0 || sscanf(buf, "\\c&H%X&%1[\\}]%n", &color, sep, &len) > 1 || sscanf(buf, "\\%1[1234]c%1[\\}]%n", c_num, sep, &len) > 1 || @@ -543,13 +550,11 @@ int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, } else if (sscanf(buf, "\\org(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) { if (callbacks->origin) callbacks->origin(priv, x1, y1); - } else { - len = strcspn(buf+1, "\\}") + 2; /* skip unknown code */ } buf += len - 1; + buf += strcspn(buf, "\\}"); // skip comments } - if (*buf++ != '}') - return AVERROR_INVALIDDATA; + buf++; // skip } } else { if (!text) { text = buf; @@ -559,7 +564,7 @@ int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, buf++; } } - if (text && callbacks->text) + if (text && callbacks->text && !drawing) callbacks->text(priv, text, text_len); if (callbacks->end) callbacks->end(priv); diff --git a/tests/ref/fate/sub-textenc b/tests/ref/fate/sub-textenc index f7d82ce..2d7236e 100644 --- a/tests/ref/fate/sub-textenc +++ b/tests/ref/fate/sub-textenc @@ -152,7 +152,7 @@ text 2 00:00:52,501 --> 00:00:54,500 Hide these tags: also hide these tags: -but show this: {normal text} +but show this: 30 00:00:54,501 --> 00:01:00,500 @@ -160,18 +160,18 @@ but show this: {normal text} \ N is a forced line break \ h is a hard space Normal spaces at the start and at the end of the line are trimmed while hard spaces are not trimmed. -The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D +The line will never break automatically right before or after a hard space. :-D 31 00:00:54,501 --> 00:00:56,500 -\h\h\h\h\hA (05 hard spaces followed by a letter) +     A (05 hard spaces followed by a letter) A (Normal spaces followed by a letter) A (No hard spaces followed by a letter) 32 00:00:56,501 --> 00:00:58,500 -\h\h\h\h\hA (05 hard spaces followed by a letter) +     A (05 hard spaces followed by a letter) A (Normal spaces followed by a letter) A (No hard spaces followed by a letter) Show this: \TEST and this: \-) @@ -179,10 +179,10 @@ Show this: \TEST and this: \-) 33 00:00:58,501 --> 00:01:00,500 -A letter followed by 05 hard spaces: A\h\h\h\h\h +A letter followed by 05 hard spaces: A      A letter followed by normal spaces: A A letter followed by no hard spaces: A -05 hard spaces between letters: A\h\h\h\h\hA +05 hard spaces between letters: A     A 5 normal spaces between letters: A A ^--Forced line break diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc index 08903e3..5f4d2b6 100644 --- a/tests/ref/fate/sub-webvttenc +++ b/tests/ref/fate/sub-webvttenc @@ -125,33 +125,33 @@ text 2 00:52.501 --> 00:54.500 Hide these tags: also hide these tags: -but show this: {normal text} +but show this: 00:54.501 --> 01:00.500 \ N is a forced line break \ h is a hard space Normal spaces at the start and at the end of the line are trimmed while hard spaces are not trimmed. -The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D +The line will never break automatically right before or after a hard space. :-D 00:54.501 --> 00:56.500 -\h\h\h\h\hA (05 hard spaces followed by a letter) +     A (05 hard spaces followed by a letter) A (Normal spaces followed by a letter) A (No hard spaces followed by a letter) 00:56.501 --> 00:58.500 -\h\h\h\h\hA (05 hard spaces followed by a letter) +     A (05 hard spaces followed by a letter) A (Normal spaces followed by a letter) A (No hard spaces followed by a letter) Show this: \TEST and this: \-) 00:58.501 --> 01:00.500 -A letter followed by 05 hard spaces: A\h\h\h\h\h +A letter followed by 05 hard spaces: A      A letter followed by normal spaces: A A letter followed by no hard spaces: A -05 hard spaces between letters: A\h\h\h\h\hA +05 hard spaces between letters: A     A 5 normal spaces between letters: A A ^--Forced line break