From patchwork Fri Jan 13 17:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ridley Combs X-Patchwork-Id: 39997 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bb05:b0:b6:a58c:cef with SMTP id fc5csp622813pzb; Fri, 13 Jan 2023 09:27:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXvcwaHJLDRliINspQBUKMmSot1EDmFM+2kxBkEy/2YZSnpPxFfASbL3l+c63NL2qc236BSF X-Received: by 2002:aa7:df8e:0:b0:49d:1a59:176b with SMTP id b14-20020aa7df8e000000b0049d1a59176bmr1102060edy.30.1673630824141; Fri, 13 Jan 2023 09:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673630824; cv=none; d=google.com; s=arc-20160816; b=Qe5jN1foP8RuwtuxVrnJsmyAey9yv9uGL4QpYgxJV6XIP/NOjC78cNyD7vn1cB6PUD EdSV+ZR1j8sQzyaS5zVYFRVYoOwgJtC6PyVJLmMS6zYMWcrZEPajXEKnS6j+hTzMm4as NLH6QMYLE6lFD9RpGC06/131TtqqSBZPqiwkqLURNWqyTfSHZrMMpPJpf1jKt6dyphe/ 9QDx5RJbRZrf0v6kg1qUzUtJXAwLLDdlc15gVGCDwuSgy6LBijRcPi43IY9mLcNYAVwQ pDt6lBuUYGnAMpcLBzfpx8pDFOqp4v4rG4p2E6euwFohHcGYHHvmcj7X0w6s1XBYvity lrKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=F29d3+prdDVJftmFPpe/ou/o7zjH7XC/8ejRcWB9Mek=; b=BWYsFSFuPhfgXK/tuBSVs4F+Xa5PWyjAbQsYt3QlJLrkxFeiRDQCNo+2U9KAxxn5nX tly+0rbBpEtzPuoZZf3zrbucZkdZo7B1mViSEDwIUTY/h4Xy7+c8IHEfwqeemwCdpbNB 7A2Ku5Sa8otydAMKB66/RjAS+8wViDXswxm1GpAPkmoJ7zwCKQwnBgHd6phseAk0/Kr9 mFfEza/SgWUTcLa+Cu4LT5lh6XcluU1jsWy35BG1mIlOrtiOFlfHe0Cn9ZUtyA+fcdD3 z78XaMbI/jO1oYeOm3wmFEyS+xfX8VSxNsk+G8Ws3qSsiIse/h0Tuc+EOSFYTh1K2IP8 jN5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=QkA9kGdS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a20-20020a17090680d400b007a835c56b70si16790758ejx.267.2023.01.13.09.27.02; Fri, 13 Jan 2023 09:27:04 -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=@rcombs.me header.s=google header.b=QkA9kGdS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81BB868BC16; Fri, 13 Jan 2023 19:26:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CC5D689BEF for ; Fri, 13 Jan 2023 19:26:53 +0200 (EET) Received: by mail-io1-f51.google.com with SMTP id p66so10791487iof.1 for ; Fri, 13 Jan 2023 09:26:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=O6dw6VH72WPXkKkkldAQrAtKvRhco3qFef7KgFR+AJE=; b=QkA9kGdSezR50rFqgsKv6DYKtQ5Xb+kHYh3Ru29OTJLq0NRF6eL+hJ1vNA8kViFrgF aBtF4DrnbqyunLfxR/d+hMJk39kD+8EgXpMbtSsW5PNA+RZgFI6tjyrWDc/fdrMB6hXd GnFm3o1gVPml4nzD2wJmmZ0MRBUoq+iYkshLP8W0R265cdniOGF58+ofeEIo6Z/rsp/e MraP02J5H2tUsGXmMIwHRaXmD0Gtojnf24/29gav7E7WNnP75TVwemHMvBzgADL0cKer 1QKTz2qCoAadnppODHVWAtDQyALSV5spVQ/NADzmr0LTeuC7GLqgh7FC6XX+ZcR9HrVN +fCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O6dw6VH72WPXkKkkldAQrAtKvRhco3qFef7KgFR+AJE=; b=yglTf85D8WccgjD2Jg6swJDpnNHy8/C17E8Inc9venj4LhUQkY7HebzNBsvzE63v2b ZUjncEFsdI/6bnliAMDIy9Smwn4xHUvPmH293BJadADwMTjBJagkJa2C30cB3682/Enj cgcrnFul3m/YDqsw6io5bOnXFv1GSK+39ptrCH7VRGcsbU3GxCrJ+dKW+3jCEj6aV5AZ RRxwYa/SMWrnSbj+7vTe1OZ9pRE3LibhCTZFiu8TwAtn/eDht71m6WpVFNcZ9xVpcQDC x6BSTuQEJvwqRF1gPZQbgrUdUUcFXaJURer17xWY+N36mY8xbz6X9IVcp18B0u2nfocd EUbg== X-Gm-Message-State: AFqh2krME08GjXu+8foy1FgmQ9bo68elQbnh2Z/zTlZD3pvfFYtjXZD6 D1LaIANiXPjKI9PNvtPa289M+AJh+5mVvWqlSA== X-Received: by 2002:a6b:4a0e:0:b0:6bc:d714:520f with SMTP id w14-20020a6b4a0e000000b006bcd714520fmr53516972iob.15.1673630811304; Fri, 13 Jan 2023 09:26:51 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:c8b9:2697:4167:e310]) by smtp.gmail.com with ESMTPSA id p32-20020a056638192000b0039e89ea68f9sm4365211jal.135.2023.01.13.09.26.50 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 13 Jan 2023 09:26:50 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Jan 2023 11:26:40 -0600 Message-Id: <20230113172640.52901-1-rcombs@rcombs.me> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavf/matroska: add support for ARIB captions 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: jQ3NMcYfqFEI Not yet ready for merge, pending finalization of the standard proposal for this mapping: https://github.com/ietf-wg-cellar/matroska-specification/pull/724 --- libavformat/matroska.c | 1 + libavformat/matroskadec.c | 30 ++++++++++++++++++++++++++++++ libavformat/matroskaenc.c | 23 +++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/libavformat/matroska.c b/libavformat/matroska.c index 90d94b65bf..79b2d09984 100644 --- a/libavformat/matroska.c +++ b/libavformat/matroska.c @@ -76,6 +76,7 @@ const CodecTags ff_mkv_codec_tags[]={ {"S_DVBSUB" , AV_CODEC_ID_DVB_SUBTITLE}, {"S_HDMV/PGS" , AV_CODEC_ID_HDMV_PGS_SUBTITLE}, {"S_HDMV/TEXTST" , AV_CODEC_ID_HDMV_TEXT_SUBTITLE}, + {"S_ARIBSUB" , AV_CODEC_ID_ARIB_CAPTION}, {"V_AV1" , AV_CODEC_ID_AV1}, {"V_AVS2" , AV_CODEC_ID_AVS2}, diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d582f566a2..3a888e3ada 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -50,6 +50,7 @@ #include "libavutil/time_internal.h" #include "libavutil/spherical.h" +#include "libavcodec/avcodec.h" #include "libavcodec/bytestream.h" #include "libavcodec/flac.h" #include "libavcodec/mpeg4audio.h" @@ -2813,6 +2814,35 @@ static int matroska_parse_tracks(AVFormatContext *s) /* we don't need any value stored in CodecPrivate. make sure that it's not exported as extradata. */ track->codec_priv.size = 0; + } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION && track->codec_priv.size == 3) { + int component_tag = track->codec_priv.data[0]; + int data_component_id = AV_RB16(track->codec_priv.data + 1); + + switch (data_component_id) { + case 0x0008: + // [0x30..0x37] are component tags utilized for + // non-mobile captioning service ("profile A"). + if (component_tag >= 0x30 && component_tag <= 0x37) { + st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_A; + } + break; + case 0x0012: + // component tag 0x87 signifies a mobile/partial reception + // (1seg) captioning service ("profile C"). + if (component_tag == 0x87) { + st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_C; + } + break; + default: + break; + } + + if (st->codecpar->profile == FF_PROFILE_UNKNOWN) + av_log(matroska->ctx, AV_LOG_WARNING, + "Unknown ARIB caption profile utilized: %02x / %04x\n", + component_tag, data_component_id); + + track->codec_priv.size = 0; } track->codec_priv.size -= extradata_offset; diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 2deb4284e8..67cfec761a 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -58,6 +58,7 @@ #include "libavutil/stereo3d.h" #include "libavcodec/av1.h" +#include "libavcodec/avcodec.h" #include "libavcodec/codec_desc.h" #include "libavcodec/xiph.h" #include "libavcodec/mpeg4audio.h" @@ -1142,6 +1143,27 @@ static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn else *size_to_reserve = MAX_PCE_SIZE; break; + case AV_CODEC_ID_ARIB_CAPTION: { + unsigned stream_identifier, data_component_id; + switch (par->profile) { + case FF_PROFILE_ARIB_PROFILE_A: + stream_identifier = 0x30; + data_component_id = 0x0008; + break; + case FF_PROFILE_ARIB_PROFILE_C: + stream_identifier = 0x87; + data_component_id = 0x0012; + break; + default: + av_log(s, AV_LOG_ERROR, + "Unset/unknown ARIB caption profile %d utilized!\n", + par->profile); + return AVERROR_INVALIDDATA; + } + avio_w8(dyn_cp, stream_identifier); + avio_wb16(dyn_cp, data_component_id); + break; + } #endif default: if (CONFIG_MATROSKA_MUXER && par->codec_id == AV_CODEC_ID_PRORES && @@ -3274,6 +3296,7 @@ static const AVCodecTag additional_subtitle_tags[] = { { AV_CODEC_ID_DVB_SUBTITLE, 0xFFFFFFFF }, { AV_CODEC_ID_DVD_SUBTITLE, 0xFFFFFFFF }, { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF }, + { AV_CODEC_ID_ARIB_CAPTION, 0xFFFFFFFF }, { AV_CODEC_ID_NONE, 0xFFFFFFFF } };