From patchwork Thu Mar 28 20:11:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marth64 X-Patchwork-Id: 47600 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1588897pzb; Thu, 28 Mar 2024 13:12:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUESSVl/byDszuFQmwoliPBhMvvnIXPRMXszdiRCEoY7xOPjNuc0vv/X9rJY2P6kMnPbrhV4+MwI/0cuUN7CqsFRFEl8J3JjpMq3g== X-Google-Smtp-Source: AGHT+IE2mEwLK9meCF34K240Z5yRtLLdU3mfTDxIqjmuixTN7xkg9A4K2Nh5egN+j+QooHnbdyPC X-Received: by 2002:a17:907:3605:b0:a47:398f:1a22 with SMTP id bk5-20020a170907360500b00a47398f1a22mr245110ejc.0.1711656724902; Thu, 28 Mar 2024 13:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711656724; cv=none; d=google.com; s=arc-20160816; b=xeEs6FSMDRI8iFzLxbZQnHHK4r4p/zJir+2BWgPydU3lEZ892sKYAO+6N+suu8/cZy m55HM01R1o/6Ep5AnGZKnwzfQc7oYTcinTeyIqAOo2DplIynQm92aWBFGLTCPGsN32OH yux6vkatSmsiXJYlULOQlXqhJKYa7fV+Lrw2nWQ4d3cIHGnCTQl3YOCANdLQs88DBIgR hbuLtWL9cNBQ4IZQZ47GTAnnJYIphcPIxreWTPY9AUw4xgKiEY+Ws7SwXVDysE1d9KnZ 3nd5reo8EcetI8Ia3X3VppOup1psR5JxQn387AYkrvJg1PYdcvmfru7IW81g1c/YmuQd tnpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=7NI35x4dUUv94MUd11HLNMj/FGvevhfk/ylr27Y34IA=; fh=PlWMzmI9LD2qGS7ipLrQl8z0iaQTLQLHzoGuXcBzpCg=; b=imM08WnZuvuEqxf6Xc3D5KWZi4uG0707X4uzMgmaCIEaaKTIw6xZFvfLnBbitt657r rF6G2R0tq2ewGGpUcAgdNpQm8B08XyvytanNuepgIpMcnxu037nCQWDzIKXF1pLQwVtl XKpgJfHDqo2dwb+gtwLfrQnF9qvQ+EE+SzFBy03CnMywAHZaoB6B+AAQAo6wmFkWCfsA NHADEdFuYJiy3izRyA4OQvv5dl9yTBRvAAezmNn03X+DHV4OtHMOHUnkgGePZ+cFajsv qaINc1QH47bEhIF52WATFCLAyNh1MfV/7eYFvThRnTDIptV7WnoeKyc9pXZVALXuwc5j PwFw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@proxyid.net header.s=google header.b=Zu6GATAv; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s24-20020a170906c31800b00a46b9fdb7a4si1053394ejz.296.2024.03.28.13.12.04; Thu, 28 Mar 2024 13:12:04 -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=@proxyid.net header.s=google header.b=Zu6GATAv; 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 BE3A068D71D; Thu, 28 Mar 2024 22:11:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f226.google.com (mail-pg1-f226.google.com [209.85.215.226]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A359568D509 for ; Thu, 28 Mar 2024 22:11:38 +0200 (EET) Received: by mail-pg1-f226.google.com with SMTP id 41be03b00d2f7-5d8b519e438so970742a12.1 for ; Thu, 28 Mar 2024 13:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxyid.net; s=google; t=1711656697; x=1712261497; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BU8eMuxMknOtFLRkxiQPhmlrle0IHWgIEE1Al1uUkTM=; b=Zu6GATAvodkYVDA58WTOv922WTkn6/Z8NPtna4b7sUKTqTzIG1Q4K20dDvv3BBz0tq vaGru25SoUBFCF8/w7pleM57iqznvkavp6IT14tujIAoAbeKB4meAeYau9EwLf5ZwMpN BNpWAdtpIbhUVF8eOROM1VdT98V7B0zyuCe99y0VNseAXcb7a35gwsRz5t8AoTlJrRxF FIE2A1XmXs/211fgjcLQAQ2WU8XIUeLjr2UmsoEmSAH9PPpogxB5Y8YBTPJZ46z64+yz 18FA36DGBirqD2Dgy9PrR6RIYk+rSaEXwYg9+ivbGJm4ej2QLcV4ZJcCXy3CYdSAr67+ 9jgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711656697; x=1712261497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BU8eMuxMknOtFLRkxiQPhmlrle0IHWgIEE1Al1uUkTM=; b=AV0CsZ6MQdUIdCMO2lByQN8lV+2RxQvyIsJEzfQeO3h7apv9L4kCDPUq8rdyB2y4mA ZhB+eTM3th4lu9lhqKv4BY27mK6Xzuj14D8l2L70qK6OEhCF+QA1CWldNDhxWNr9FCVM u8seCxlj4ecxoQm1piYK6OB28aypEhrb4KBz3sHFVUnDilNKsllsJ+upEUAe2yM1Psze /lBXDnsG1xwg/msBe5pagFJkS4N8gETLIduaHDWkIvr0OjZFjiYZ/Tu0VIWblA/w8c8k wmZtalJOxSUC7Ax2UlpuiOoRNFQuU1PIRiFktHaLpgMIL7vGq88a606FUH0PDndmd0O1 0oYA== X-Gm-Message-State: AOJu0YyAFZwD7R/V4SinOuqFp32/my1an66YdL4BUEIJI7RqtkVlXpSu X0B2QfmT7LQYhQrynVt1zl9zZIAdwknDoSSkoCzjWZFT9q3yL4tUepduNfsaB933KAChKr7QYp/ nBYsf0CdKl+tXDrJch7q5mxmbk3l9s056wvNdlJP0 X-Received: by 2002:a17:903:248:b0:1e0:f51b:12e2 with SMTP id j8-20020a170903024800b001e0f51b12e2mr590770plh.2.1711656696932; Thu, 28 Mar 2024 13:11:36 -0700 (PDT) Received: from wsx-cc1-001.. (c-76-141-249-38.hsd1.il.comcast.net. [76.141.249.38]) by smtp-relay.gmail.com with ESMTPS id b8-20020a170902d88800b001e0c9462e9fsm61791plz.57.2024.03.28.13.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 13:11:36 -0700 (PDT) X-Relaying-Domain: proxyid.net From: Marth64 To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 15:11:29 -0500 Message-Id: <20240328201132.1804716-3-marth64@proxyid.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328201132.1804716-1-marth64@proxyid.net> References: <20240328201132.1804716-1-marth64@proxyid.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v10 2/5] avformat/rcwtdec: add RCWT Closed Captions demuxer 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 Cc: Marth64 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: mqFSZ3QRQAfY RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly used OSS tool for processing 608/708 Closed Captions (CC). RCWT can be used to archive the original extracted CC bitstream. The muxer was added in January 2024. In this commit, add the demuxer. One can now demux RCWT files for rendering in ccaption_dec or interop with ccextractor (which produces RCWT). Using the muxer/demuxer combo, the CC bits can be kept for processing or rendering with either tool. This can be an effective way to backup an original CC stream, including format extensions like EIA-708 and overall original presentation. Signed-off-by: Marth64 --- doc/demuxers.texi | 30 ++++++++++ libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/rcwtdec.c | 123 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 libavformat/rcwtdec.c diff --git a/doc/demuxers.texi b/doc/demuxers.texi index b70f3a38d7..04293c4813 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -1038,6 +1038,36 @@ the command: ffplay -f rawvideo -pixel_format rgb24 -video_size 320x240 -framerate 10 input.raw @end example +@anchor{rcwtdec} +@section rcwt + +RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly +used open source tool for processing 608/708 Closed Captions (CC) sources. +For more information on the format, see @ref{rcwtenc,,,ffmpeg-formats}. + +This demuxer implements the specification as of March 2024, which has +been stable and unchanged since April 2014. + +@subsection Examples + +@itemize +@item +Render CC to ASS using the built-in decoder: +@example +ffmpeg -i CC.rcwt.bin CC.ass +@end example +Note that if your output appears to be empty, you may have to manually +set the decoder's @option{data_field} option to pick the desired CC substream. + +@item +Convert an RCWT backup to Scenarist (SCC) format: +@example +ffmpeg -i CC.rcwt.bin -c:s copy CC.scc +@end example +Note that the SCC format does not support all of the possible CC extensions +that can be stored in RCWT (such as EIA-708). +@end itemize + @section sbg SBaGen script demuxer. diff --git a/libavformat/Makefile b/libavformat/Makefile index 44aa485029..5d77cba7f1 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -493,6 +493,7 @@ OBJS-$(CONFIG_QOA_DEMUXER) += qoadec.o OBJS-$(CONFIG_R3D_DEMUXER) += r3d.o OBJS-$(CONFIG_RAWVIDEO_DEMUXER) += rawvideodec.o OBJS-$(CONFIG_RAWVIDEO_MUXER) += rawenc.o +OBJS-$(CONFIG_RCWT_DEMUXER) += rcwtdec.o subtitles.o OBJS-$(CONFIG_RCWT_MUXER) += rcwtenc.o subtitles.o OBJS-$(CONFIG_REALTEXT_DEMUXER) += realtextdec.o subtitles.o OBJS-$(CONFIG_REDSPARK_DEMUXER) += redspark.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 9df42bb87a..ae925dcf60 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -391,6 +391,7 @@ extern const FFInputFormat ff_qoa_demuxer; extern const FFInputFormat ff_r3d_demuxer; extern const FFInputFormat ff_rawvideo_demuxer; extern const FFOutputFormat ff_rawvideo_muxer; +extern const FFInputFormat ff_rcwt_demuxer; extern const FFOutputFormat ff_rcwt_muxer; extern const FFInputFormat ff_realtext_demuxer; extern const FFInputFormat ff_redspark_demuxer; diff --git a/libavformat/rcwtdec.c b/libavformat/rcwtdec.c new file mode 100644 index 0000000000..91f994c3ab --- /dev/null +++ b/libavformat/rcwtdec.c @@ -0,0 +1,123 @@ +/* + * RCWT (Raw Captions With Time) demuxer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly + * used open source tool for processing 608/708 Closed Captions (CC) sources. + * + * This demuxer implements the specification as of March 2024, which has + * been stable and unchanged since April 2014. + * + * A free specification of RCWT can be found here: + * @url{https://github.com/CCExtractor/ccextractor/blob/master/docs/BINARY_FILE_FORMAT.TXT} + */ + +#include "avformat.h" +#include "demux.h" +#include "internal.h" +#include "subtitles.h" +#include "libavutil/intreadwrite.h" + +#define RCWT_HEADER_SIZE 11 + +typedef struct RCWTContext { + FFDemuxSubtitlesQueue q; +} RCWTContext; + +static int rcwt_read_header(AVFormatContext *avf) +{ + RCWTContext *rcwt = avf->priv_data; + + AVStream *st; + uint8_t header[RCWT_HEADER_SIZE]; + int ret; + + /* read header */ + ret = ffio_read_size(avf->pb, header, RCWT_HEADER_SIZE); + if (ret < 0) + return ret; + + if (AV_RB16(header + 6) != 0x0001) { + av_log(avf, AV_LOG_ERROR, "RCWT format version is not compatible " + "(only version 0.001 is known)\n"); + return AVERROR_INVALIDDATA; + } + + av_log(avf, AV_LOG_DEBUG, "RCWT writer application: %02X version: %02x\n", + header[3], header[5]); + + /* setup stream */ + st = avformat_new_stream(avf, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_EIA_608; + + avpriv_set_pts_info(st, 64, 1, 1000); + + /* demux */ + while (!avio_feof(avf->pb)) { + AVPacket *sub; + int64_t cluster_pos = avio_tell(avf->pb); + int64_t cluster_pts = avio_rl64(avf->pb); + int cluster_nb_blocks = avio_rl16(avf->pb); + + if (cluster_nb_blocks == 0) + continue; + + sub = ff_subtitles_queue_insert(&rcwt->q, NULL, 0, 0); + if (!sub) + return AVERROR(ENOMEM); + + ret = av_get_packet(avf->pb, sub, cluster_nb_blocks * 3); + if (ret < 0) + return ret; + + sub->pos = cluster_pos; + sub->pts = cluster_pts; + } + + ff_subtitles_queue_finalize(avf, &rcwt->q); + + return 0; +} + +static int rcwt_probe(const AVProbeData *p) +{ + return p->buf_size > RCWT_HEADER_SIZE && + AV_RB16(p->buf) == 0xCCCC && + AV_RB8(p->buf + 2) == 0xED && + AV_RB16(p->buf + 6) == 0x0001 ? 50 : 0; +} + +const FFInputFormat ff_rcwt_demuxer = { + .p.name = "rcwt", + .p.long_name = NULL_IF_CONFIG_SMALL("RCWT (Raw Captions With Time)"), + .p.extensions = "bin", + .p.flags = AVFMT_TS_DISCONT, + .priv_data_size = sizeof(RCWTContext), + .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP, + .read_probe = rcwt_probe, + .read_header = rcwt_read_header, + .read_packet = ff_subtitles_read_packet, + .read_seek2 = ff_subtitles_read_seek, + .read_close = ff_subtitles_read_close +};