From patchwork Tue Apr 28 06:18:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Pack X-Patchwork-Id: 19333 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:3c87:0:0:0:0:0 with SMTP id j129csp3804695yba; Mon, 27 Apr 2020 23:19:03 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0SdHHWbzVku9/X7W0OKtKtzmU+xGmNQTzrzE3VGdA7uo8T42EZafKvxiFkT0ywJH/gO8y X-Received: by 2002:a1c:7905:: with SMTP id l5mr2888810wme.5.1588054743552; Mon, 27 Apr 2020 23:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588054743; cv=none; d=google.com; s=arc-20160816; b=USS1x3XmvuWDCToB7vKi0oAGyJavcDy+YaQhW0F/+6ZaC4FzrhCKOEI42GBtbGDPHo qB9zTasCIKh13FcLkqVh2Fdgh9PFWxWItsdxrCaQl0obfbgW++sKXGxZKYydNO6U+5rZ 4M0f6jEaLBSIWFFedZtg+rPNKmE7Ws5paKc1cFs/kIc3zSPiPqXjcuAM7mDkODLEA2Kd xQBNEsJOKdMOGP1ayg5fpKL1ubFps4Olh1ar2j4i4a5GP4ihqytIqHS1LtjUMFtv7ae+ pRWuGIc/S6f8KxZ61gZ4uBLNE0dXbp3YUoi4uMp0P7LmEoz98MKo4EWi51g9kQ7+0LFX yTKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=Phpmu7E85WxWy4DrhYPkajZgV1m+rYZ52O6nSnaUqmk=; b=C23eOyg/RCDtCRemcSTkmk3/Nj97PQLTQXgbgbR/Xck6kbbgId5sHF80zLqEw/ltQ4 sWOF5s+RQU+oaeHrrahu09HAYYrygzwhVa6t5j96y3zY4l/ZctV1gzFdpN7CGAPo6Uos kh998fuwKQ2uOYNhqkQXosDxoPXiTRptx0129xUvudBzkxaQNhj6bFZejvd7lKBySLaU u6KltKAp3mOF432w9+wg5c9wkGEe3hufG1AlhJIG7dMjprcnyhpPsVFNeYBxdX1MkRoS UN78Hd6SH9aSOEgmG05qevmu8d+Tyz8s+P2xQrTmewGkRndi1PTlc8WlYximUSHLg8e4 TBkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=CHEfyO9o; 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 b207si1381579wmd.219.2020.04.27.23.19.03; Mon, 27 Apr 2020 23:19:03 -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=CHEfyO9o; 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 73F9B68BCF1; Tue, 28 Apr 2020 09:19:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B226568BBAE for ; Tue, 28 Apr 2020 09:18:56 +0300 (EEST) Received: by mail-lf1-f68.google.com with SMTP id k28so15878606lfe.10 for ; Mon, 27 Apr 2020 23:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=aa6DBdGKNpv3RMRiwKe1RPtq5jraalUrKKagahPxgOQ=; b=CHEfyO9oI1NGQxd3RvwdLlFkaQ0jMjuwskIKHdYJLalwkMWtt7qOQIAS7QmKbbflkR q104wpa8AHH9r0UddDla4TkjWjhQQLs1H+f6FvSJHBUt6rU+eWikuAwdOHtdb1Mi5x/X MlPQ6FvUTb18SMcYF8LENljS6m6xB1c/LJCGgPSHag6+GKK3zUB7v1IpbDdKtQhU3/QB Zija75epMaETt/6OeJFSohLqX7NmlQc2+rWWhiV+z/EeR5j1R6T4f4Nsej9M21eWA/+O tpKUw/CvyZAfZLBnswqpNDWIzsqqmdj3pmKgtCPozOl6Q6fmH9ywsTvh7JohBeUwT24/ Am4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=aa6DBdGKNpv3RMRiwKe1RPtq5jraalUrKKagahPxgOQ=; b=W3T0iFy2XzU+5wkJgKIlnO+U4NKKSZaTc/n9Wk9Qf7WQ4wb3zs298s/sAd4pYmIKBM S2SEbgXhc2eZJPsAMmmZkL8xi7pbzckfIDa80n+H3MYGxX6/3R4lmGbq7BgJA/Blb5JA leFn+wvEOW4R+0/DmZrCIdPm9J9DNhk1ytNQzRetHWdOIoKhJ7nb6lchjqpQSY+tislN 7c2f71beHDpaTThU3Ti5WBIv2wwTlPefircPiQrkcu1hOUvo6Xc5ZzHncrWvgFS4Ys/E FVcVYQjDkf1sgxLYqqzGs+Z8oWGdPmhQSoQFgxzah81Gly2uXAvE7xydIQfObuM4NxsR mJqw== X-Gm-Message-State: AGi0PuZ56gFL5tt0LvZI1XfJ7Qu69K6Ex4vhW4H7WRJBW+s9dvLq3U+3 recH4qpNvA2B4i5B3+k1uavvuROnGndvJ8AfQ7hIGotUb8Y= X-Received: by 2002:ac2:5395:: with SMTP id g21mr17879951lfh.61.1588054735950; Mon, 27 Apr 2020 23:18:55 -0700 (PDT) MIME-Version: 1.0 From: Roger Pack Date: Tue, 28 Apr 2020 00:18:46 -0600 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH 2/3] closed caption decoder: add new parameter to allow output to avoid repeated lines 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" X-TUID: 9/B8qML04BER I didn't actually *need* this but thought the functionality was very nice to have, so here's my contribution. It allows for forcing "rollup" style closed captions to output one line at a time (basically, when there is a carriage return, it outputs a line), so there is never any duplication in the output, for instance if it's converted to .srt or .vtt files. Without this you have output like this: 00:01.536 --> 00:03.605 AND AS A SECONDARY QUESTION, I 00:03.605 --> 00:05.707 AND AS A SECONDARY QUESTION, I WOULD ASK YOU HOW OUR VETERANS 00:05.706 --> 00:09.343 WOULD ASK YOU HOW OUR VETERANS AND ACTIVE DUTY MILITARY HAVE 00:09.344 --> 00:10.412 AND ACTIVE DUTY MILITARY HAVE FARED UNDER THIS COMMANDER IN With it set to "1" you get output like this: 00:02.014 --> 00:03.049 SOLDIERS HOME IN HOLYOKE, 00:03.048 --> 00:04.116 MASSACHUSETTS, HAVE LOST 73. 00:04.116 --> 00:04.850 ANOTHER FACILITY IN NEW ORLEANS, 00:04.850 --> 00:06.184 53. 00:06.184 --> 00:07.753 VETERANS ARE IN REAL PERIL 00:07.753 --> 00:14.193 BECAUSE OF A LACK OF PREPARATION 00:14.193 --> 00:15.727 AND THEN THE SAME DYSFUNCTION ... Thanks. Signed-off-by: rogerdpack --- doc/decoders.texi | 62 +++++++++++++++++++++++++++++++++++++++ libavcodec/ccaption_dec.c | 11 +++++-- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/doc/decoders.texi b/doc/decoders.texi index 0c5a39bc9c..b4601d7e3c 100644 --- a/doc/decoders.texi +++ b/doc/decoders.texi @@ -252,6 +252,68 @@ Enabled by default. @end table +@section cc_dec_raw_608 + +Closed Caption decoder. +Decodes "raw 608 byte pairs" closed captions. + +@subsection Options + +@table @option +@item real_time +Specifies if the decoder should output "the current screen" +after each new character appears (in general, with closed +captions, one new character can appear per frame). +Default is false, decoder outputs "the current screen" +only when a line feed occurs. + +@item rollup_override_line_count +Specifies the number of lines to output (if the closed +caption is using rollup, which is common). +Typically the stream itself designates how many lines of +closed caption material to display on the screen. +This is typically more than one and means some lines are +repeated in the output, since output occurs with each carriage +return. +Default is "0" (starts in rollup mode with line count 2, +then then changes to whatever the closed caption stream +later specifies). +If you want a line output (no duplication), set this value to "1". + +@end table + +@section dvbsub +@section cc_dec + +Closed Caption decoder. + +Decodes "608 over 708" closed captions. + +@subsection Options + +@table @option +@item real_time +Specifies if the decoder should output "the current screen" +after each new character appears (in general, with closed +captions, one new character can appear per frame). +Default is false, decoder outputs "the current screen" +only when a line feed occurs. + +@item rollup_override_line_count +Specifies the number of lines to output (if the closed +caption is using rollup, which is common). +Typically the stream itself designates how many lines of +closed caption material to display on the screen. +This is typically more than one and means some lines are +repeated in the output, since output occurs with each carriage +return. +Default is "0" (starts in rollup mode with line count 2, +then then changes to whatever the closed caption stream +later specifies). +If you want a line output (no duplication), set this value to "1". + +@end table + @section dvbsub @subsection Options diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index 07091f4572..8cd948d709 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -238,6 +238,7 @@ typedef struct CCaptionSubContext { AVBPrint buffer; int buffer_changed; int rollup; + int rollup_override_line_count; enum cc_mode mode; int64_t start_time; /* visible screen time */ @@ -261,7 +262,7 @@ static av_cold int init_decoder(AVCodecContext *avctx) av_bprint_init(&ctx->buffer, 0, AV_BPRINT_SIZE_UNLIMITED); /* taking by default roll up to 2 */ ctx->mode = CCMODE_ROLLUP; - ctx->rollup = 2; + ctx->rollup = ctx->rollup_override_line_count || 2; ctx->cursor_row = 10; ret = ff_ass_subtitle_header(avctx, "Monospace", ASS_DEFAULT_FONT_SIZE, @@ -697,7 +698,12 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint case 0x25: case 0x26: case 0x27: - ctx->rollup = lo - 0x23; + if (ctx->rollup_override_line_count) { + ctx->rollup = ctx->rollup_override_line_count; + } else { + ctx->rollup = (lo - 0x23); + } + av_log(ctx, AV_LOG_DEBUG, "setting rollup to %d, requested from stream was %d, override is %d\n", ctx->rollup, (lo - 0x23), ctx->rollup_override_line_count); ctx->mode = CCMODE_ROLLUP; break; case 0x29: @@ -842,6 +848,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { { "real_time", "emit subtitle events as they are decoded for real-time display", OFFSET(real_time), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, SD }, + { "rollup_override_line_count", "force number of rollup lines [overrides any number specified by the captions themselves]", OFFSET(rollup_override_line_count), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, SD }, {NULL} }; -- 2.17.1