From patchwork Tue Apr 6 08:18:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zheng qian X-Patchwork-Id: 26777 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 81414449B3D for ; Tue, 6 Apr 2021 11:45:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 59486689E13; Tue, 6 Apr 2021 11:45:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6EC4B687F09 for ; Tue, 6 Apr 2021 11:45:40 +0300 (EEST) Received: by mail-qv1-f50.google.com with SMTP id fn8so1891842qvb.5 for ; Tue, 06 Apr 2021 01:45:40 -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:mime-version :content-transfer-encoding; bh=mNh7r+nQXtCZHSX8zFCglPggItqcNvg0gVz5A5QWlDc=; b=waP4eDJYdWyoTT4GhKR5wIDQVKAfZ9sTQ2pOG+hX/JCT/yoKqnUprcECj6NtyVNus6 2ZgKEfzY6WrzGHv8N/rXaXbck8HKIbsPlELtcTFfltZaJ3GTbx0ZtabbTTzdD8ocAqCL rUUogiha7ypz/6fE4kwhYitM5NI1wRUuPZJzRQGgykmopWiYIZhyAH7OyWliAVQqiQtn aQ5S6hn8wX5ZM6wpVNjvDNok9PVOyBhfO3AtYggCr/XAJ9XRWU20wXIQ37qILXlq6MSq FNZNBpTtblbG9qpgR3/wkipXe52s3q6ZKGQ08NbhH1KzKBPEK2rMzVuRkbhqGOVvI2kB FJ6A== 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:mime-version :content-transfer-encoding; bh=mNh7r+nQXtCZHSX8zFCglPggItqcNvg0gVz5A5QWlDc=; b=AKxDoabszmVSG65v5Hhog3IbqDh6aYqi8Vyfeysue09jE3z6qcJkoR/OkOkki9287v AUqlU2zxx2u6rCB0s5qi8CReRYawNz3C9wiMUrwtH1BDmYasLjU9NzuZmgNNLh16E9KQ PX+UEbqLQ1UDWi4WZVcHSrfy3OFxHLApiZ1NBWPAZpJ/QxHmxvFrTFXcaTMJH9F8zoXe gMDoF+iXXihCI6/cvx7U+ACGH9SrAV6YjzprDZzKaCIQqMpR5QFWZp8YANk/m0YN91pH IZ5AOLQi1hQ3lnqS3otM0Ijagp23MKgXLR94RBo4s2nF52/6ojxwKI4svAJA06y7b1CV 2ciA== X-Gm-Message-State: AOAM5306uPBgOS/rl0ClTUnMiYwbyIHUmWZwO+f9uysj1cueQ2fkzDHJ 6qm9B9/EF6qJQ9TbnbrNDyxAumk3SK0isSlf X-Google-Smtp-Source: ABdhPJygoiAGlPfnAmya/mduYVuOadQsgaylspe17ayUjRBKwyTeDrwse5OQJxsBSc8OAPG2jPds2A== X-Received: by 2002:a17:902:e54b:b029:e6:b39f:63ab with SMTP id n11-20020a170902e54bb02900e6b39f63abmr28106624plf.55.1617697165250; Tue, 06 Apr 2021 01:19:25 -0700 (PDT) Received: from zhengqian-xps.lan (ngn-nat1.v4.open.ad.jp. [202.222.12.138]) by smtp.gmail.com with ESMTPSA id a13sm1218075pjd.6.2021.04.06.01.19.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Apr 2021 01:19:24 -0700 (PDT) From: zheng qian To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Apr 2021 17:18:15 +0900 Message-Id: <20210406081816.54105-1-xqq@xqq.im> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 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 , jeebjp@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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..a6a534a277 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) + return AVERROR_INVALIDDATA; + // 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 */