From patchwork Sat Apr 10 03:10:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zheng qian X-Patchwork-Id: 26827 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9CCAF4496E8 for ; Sat, 10 Apr 2021 06:20:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6F96C6806AA; Sat, 10 Apr 2021 06:20:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1DEC6805D6 for ; Sat, 10 Apr 2021 06:20:42 +0300 (EEST) Received: by mail-vs1-f47.google.com with SMTP id d65so3895272vsd.6 for ; Fri, 09 Apr 2021 20:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xqq-im.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tEuGXwr17WX6qNp+qJ1EHyl0uqZFxp0+PKhSjiBrFsU=; b=Gv2WICtcAC0cEPOLPE7KvjUwZ7aL3jIg5mVXkRcaV2cPrGj0rMd742uZ1vfyhEBck1 XoX4w6N5rXavZimn400KcNT4PrlyXQnClRQpmqWCXEADlrNBqy/OZLp2cB7z1Ii1K2xz 4QFz5ssr0Ge3bF7XayE5F8ZVLCzw6hstYJrdZ+T0pcbsj1EWJzHklpVqhUdC10ZKmHd1 tQpDCFkhtKRjB85kQsTuZ0jFv9UzjgrHNfRngYwLN+SESJoaqvp15Dl+plYcbSMaZ94I 6xoYvqLXUC6V0uhGxZQl5H45ubwUYTGcVoA8GHDS164m/3VfrD69fbUnSO30rsF7V+kY xb2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tEuGXwr17WX6qNp+qJ1EHyl0uqZFxp0+PKhSjiBrFsU=; b=bM+mga4SwhG05XlNXTZPSlnPB9P2c43yg2VEvPttCxSv2wW85U/A19oTzvoiaw9PaA Q96xeC81YwH2bQZJzFB2MzqJw4DhlIhPgHxnJHBMdLR0vzdGwL4I7PGmrPJAcJ5mi2+k mO8lOr8ZAXFH9aB5Y4w0xllyKkBUnRNmhrT3qpwt0RwwiSct6o2QekY3fvmgrpLbMsFb UUaivVf7dxklJvJNm3DqE7DMwFK3FZwTD3HTbE7dS9qK0wzKxqXBQPai71P7OWpxm+vn Lb4Pp25d7pfO7HY6e4TddKs1WJE+pFudeO2weRlb8ZYrrOfzDqWPhw+Vfe5VOrFzrIPL c4tA== X-Gm-Message-State: AOAM531YP6hMPAyKqxcWC6di/d7WBeMKDC2XQjExiCwLIFLWaqWYnd0w SAzfqiiUlpeuNK0ez4P9DrYnnmDZEFkHFFH8 X-Google-Smtp-Source: ABdhPJzdNI/yU2egx7AFCjMgm6H0hBwM40E32VNY+CCmdR6uututi3q3t0kkIu+9d5j4OdewY61HJg== X-Received: by 2002:a05:6a00:2348:b029:21d:4e83:7898 with SMTP id j8-20020a056a002348b029021d4e837898mr15352047pfj.65.1618024340882; Fri, 09 Apr 2021 20:12:20 -0700 (PDT) Received: from zhengqian-xps.lan (ngn-nat1.v4.open.ad.jp. [202.222.12.138]) by smtp.gmail.com with ESMTPSA id u14sm3300035pji.15.2021.04.09.20.12.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 20:12:19 -0700 (PDT) From: zheng qian To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Apr 2021 12:10:16 +0900 Message-Id: <20210410031017.1271-1-xqq@xqq.im> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210406081816.54105-1-xqq@xqq.im> References: <20210406081816.54105-1-xqq@xqq.im> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata 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 Cc: zheng qian Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Changes since v1: If desc_len < 3, break the switch statement instead of return AVERROR_INVALIDDATA to make it more robust. For arib_caption, data_component_descriptor should contains at least 3 bytes: data_component_id: uint16, additional_arib_caption_info: uint8. The recognization of ARIB STD-B24 caption has been introduced in commit a03885b, which is used as closed caption in Japanese / Brazilian Digital Television. But whenever copying arib_caption into mpegts output, arib_caption inside the outputted stream cannot be recgonized as a arib_caption subtitle track once again, which is caused by the missing of descriptors in the PMT table. These patches are intended to fix broken stream copying of arib_caption subtitle. This patch extracts necessary fields into codecpar->extradata for future remuxing, which describe the stream_identifier, the profile and other additional information. Signed-off-by: zheng qian --- libavformat/mpegts.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 6e0d9d7496..fd7ea1f504 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2107,6 +2107,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type // STD-B24, fascicle 3, chapter 4 defines private_stream_1 // for captions if (stream_type == STREAM_TYPE_PRIVATE_DATA) { + if (desc_len < 3) + break; + // This structure is defined in STD-B10, part 1, listing 5.4 and // part 2, 6.2.20). // Listing of data_component_ids is in STD-B10, part 2, Annex J. @@ -2145,6 +2148,28 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type st->codecpar->codec_id = AV_CODEC_ID_ARIB_CAPTION; st->codecpar->profile = picked_profile; st->internal->request_probe = 0; + + // Store stream_identifier and payload of data_component_descriptor + // (data_component_id & additional_arib_caption_info) as extradata. + // data_component_descriptor is defined in ARIB STD-B10, part 2, 6.2.20 + // These will be useful for remuxing arib_caption into mpegts output. + if (!st->codecpar->extradata) { + st->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) + return AVERROR(ENOMEM); + + st->codecpar->extradata_size = 4; + + // stream_identifier (component_tag of stream_identifier_descriptor) + st->codecpar->extradata[0] = (uint8_t)(st->stream_identifier - 1); + + // payload of data_component_descriptor structure + // data_component_id + st->codecpar->extradata[1] = (uint8_t)((data_component_id & 0xF0) >> 8); + st->codecpar->extradata[2] = (uint8_t)(data_component_id & 0x0F); + // additional_arib_caption_info, defined in ARIB STD-B24, fascicle 1, Part 3, 9.6.1 + st->codecpar->extradata[3] = get8(pp, desc_end); + } } break; case 0xb0: /* DOVI video stream descriptor */