From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id BA4804986D for ; Thu, 21 Mar 2024 16:13:09 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2833868D55D; Thu, 21 Mar 2024 18:13:06 +0200 (EET) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2087.outbound.protection.outlook.com [40.92.59.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B793668CA66 for ; Thu, 21 Mar 2024 18:12:59 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gajHAk9igLoiKaJFyLY+xhxqnblpTpFcHi21IggV16bgSOmsgIMOhjTSNcK76vD/Ib0UoArXqyc8cUkN0XJAZ27EX2uQzN6BlmPayVAIK2eMG3MYJGEsWQly2lBhOOPYNO9nZkZJgC1M4orSObPdk5dj3yWMywbISewux59GfuBZDDBXgF+byFz1XqefrzkCVi2zm8hdUNgLSgFeVuFwzpJTmWxk/8tXdA9MNl1zSAvvrhY2bxVt2t4vsNHnsRDjgkMh0nU+Rx9NZyusGSyQOFOVCNmEa9ciKqos6jewtUhizP57eBn35f1v2zNlAKYmuCTQKd8P1FNcocRsmherTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1XuRjmQfUDVDimq7mpg7sCtgyWVoAlGm5jpdn6Ln7gY=; b=JZNoOFNRyLLvOjzNjZpz+/JNB3VerhHv35LGq3z439xQRKc+2tG3mSuixGTZZdb/B0J9rcuSWIiFDCNlOkK2SYu3oGOHbodjYrrOD8YG441pheZPWMbZqEhWcEI4nEVIW3DwpxlVyJXbjUp21S85nnEimG9wW/5OkHRkjU0DqyEtXfWwhewIziO+ewe/widQN8QzTM5xeqcafausykQ7CmKppPuCm+YO5+jXAUDWesJnZP9SazsNx1y8idyh2jgvY9ZTk94SOSnd6u8up7sTHXdEWWeyGmzQO7+MD0wMhPg/E29VR5d18L+N/n1kWD605FmM70o7TC4vxFZgyjcMUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1XuRjmQfUDVDimq7mpg7sCtgyWVoAlGm5jpdn6Ln7gY=; b=e6fWn/W48s6ypUyJmhmLXVZ73NDYlg8TpnfOw/cd6Kc9kG38Ax2UHTv8FQkiucrgTus2oK9PUSrsGpvylwZwZPlARBD7c2k/QgcKodFi6fz59aWeqmICV5K4tGOQv/6f/2jrSDt3bzJjFbvXCROF9lMManIkKU3l09/HT3Rb74GWNOguW7g0MrugFQKdebazpZzryQpKzTBewPep5px7gKHJga+7rQQvveCLeRzFza6ZQ+Wy7QXgvwe1g/WJZGzYzisBMra5eGXeVxmv83EQwgCaoLS9BJ88fRqzVCHI9s/Qvxm3PM1SgMFIQXsxy+U//5Zk+Cqx6zR9PAF4seeUMA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PR3P250MB0353.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:17c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.15; Thu, 21 Mar 2024 16:12:56 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7386.025; Thu, 21 Mar 2024 16:12:56 +0000 Message-ID: Date: Thu, 21 Mar 2024 17:12:51 +0100 User-Agent: Mozilla Thunderbird Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20240321035207.3849560-1-marth64@proxyid.net> <20240321035207.3849560-3-marth64@proxyid.net> From: Andreas Rheinhardt In-Reply-To: <20240321035207.3849560-3-marth64@proxyid.net> X-TMN: [EqMlRzNXyLjyEhRoOZ2dI7mJaSEUoFtJ+YfW9MKZiSg=] X-ClientProxiedBy: FR3P281CA0071.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:4b::7) To DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) X-Microsoft-Original-Message-ID: <8e9f6029-a8f3-48fc-abd4-7ffc77cba1fe@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PR3P250MB0353:EE_ X-MS-Office365-Filtering-Correlation-Id: 848cb378-fb25-4780-e45f-08dc49c1c2e5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3CLmA9mb7SrZ0fYBZGneqAEh+sK/xrcon6eJQtbVOigy+6PLY1pI/oUqicWBFAcpxlgxorFQ/3syR6rIVlP6XfbtoGVvtc/TUuI5/urrQMbfVmd/ddxtCc8XO+v4qJdPpvFJv+ZHVWI7tRqhM7Jf7xufCDKaW8N576dYoxk90ACOMo9rV5gy0/eNlDH6qokwLTbSrmuHwCvoa8R7zG1GG6gR/CLr+Ex9oqcBXT5oUwHm79CbmIDU+5Mi4jmQT1jdCT6G8h+qp7ysziwIy8Z6PHsIL+fnh2JnV9SOXT4G+QcGGGtCgoQpXqGz0se0BOCRStYPiP+UskVwBl6xf+maZOQ7AhGwS10g6zJhnUF70pMotSg9+zeSMZFMaErHMiv22V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SWNWQS9s?= =?utf-8?B?UG9DbXZjdytsMGJrL21LQmU5QkgzN2graXdBblZTR0ZmcjFGNnNDaTVzWCtY?= =?utf-8?B?ZW04a3QrcUo1Y3dEQ1NZU3RDbFVuY3JIMEJCMlBHMWJHbjlDcHRBa2pVdmUw?= =?utf-8?B?Rm9vcFFyOEQrR1NocUd3ZHo5bWxvN08xdlV2dDZZZmNIWUluTG5aY1ZBQThP?= =?utf-8?B?Y2o3UFZxZFgyaSttcHVTVitOZ1pYTCs2WGtUWkd2TzRTRUVBWWRhZmR3PT0=?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 848cb378-fb25-4780-e45f-08dc49c1c2e5 X-MS-Exchange-CrossTenant-AuthSource: DU0P250MB0747.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2024 16:12:56.1994 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3P250MB0353 Subject: Re: [FFmpeg-devel] [PATCH v7 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Marth64: > 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 > --- > Changelog | 2 +- > doc/demuxers.texi | 30 ++++++++++ > libavformat/Makefile | 1 + > libavformat/allformats.c | 1 + > libavformat/rcwtdec.c | 123 +++++++++++++++++++++++++++++++++++++++ > 5 files changed, 156 insertions(+), 1 deletion(-) > create mode 100644 libavformat/rcwtdec.c > > diff --git a/Changelog b/Changelog > index e3ca52430c..0ae05c6cce 100644 > --- a/Changelog > +++ b/Changelog > @@ -19,7 +19,7 @@ version : > - lavu/eval: introduce randomi() function in expressions > - VVC decoder > - fsync filter > -- Raw Captions with Time (RCWT) closed caption muxer > +- RCWT (Raw Captions with Time) Closed Captions muxer and demuxer > - ffmpeg CLI -bsf option may now be used for input as well as output > - ffmpeg CLI options may now be used as -/opt , which is equivalent > to -opt > > diff --git a/doc/demuxers.texi b/doc/demuxers.texi > index b70f3a38d7..b4c4daacd9 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 Closed Captions to ASS, using the CC decoder (cc_dec): > +@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 SCC format, using the SCC muxer (scc): > +@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 formats > +that can be stored in RCWT. > +@end itemize > + > @section sbg > > SBaGen script demuxer. > diff --git a/libavformat/Makefile b/libavformat/Makefile > index 94a949f555..a6de720d8c 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 e15d0fa6d7..3140018f8d 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..e5cd05ea3e > --- /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 nb_bytes; > + > + /* read header */ > + nb_bytes = ffio_read_size(avf->pb, header, RCWT_HEADER_SIZE); > + if (nb_bytes != RCWT_HEADER_SIZE) > + return AVERROR_INVALIDDATA; ret = ffio_read_size() if (ret < 0) return ret; (I dislike that we return AVERROR_INVALIDDATA when a file is truncated; IMO a dedicated error code for that would be better and if one were ever introduced, my code above would automatically use if ffio_read_size() alone is updated.) > + > + 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; > + int ret; > + 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); > + > + if ((ret = av_get_packet(avf->pb, sub, cluster_nb_blocks * 3)) < 0) Please avoid the "if ((ret = func()) < 0)" style (see fbf1e5135298b for why; I am not claiming that your code is affected by this). > + 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_FMT_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 > +}; _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".