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 */ From patchwork Sat Apr 10 03:10:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zheng qian X-Patchwork-Id: 26828 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 38853448B3C for ; Sat, 10 Apr 2021 06:36:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0F50A687FA3; Sat, 10 Apr 2021 06:36:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ACBE0687F43 for ; Sat, 10 Apr 2021 06:36:32 +0300 (EEST) Received: by mail-il1-f169.google.com with SMTP id w2so6318379ilj.12 for ; Fri, 09 Apr 2021 20:36:32 -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=G4yjpqg1rAnA18mh0/EoXwqcDONKdK9GkPldrOAq/vE=; b=0bbpGpDHNqVckdKbl3TZHONn0iaf9DeiRBeMmjzOsc+sOfuknK9m6VjCTZN7IAKyxB RRWZe+ejaIZMixZqmPcJ0yznbIAyPRCtSw2ugzagpScfN9d9N74ivGr2odTsDMbyZO9/ U2lLaK5GU7mTnlIHD9SYtw/8bGqn+hCucOXEnbg2s9XgBE2daa/rkgpXEuLTFfmH8D+D vmkLxUVpeLnCUR6vVy4F98qKRYMrfNn3Y3QdA1plPp8WWk3Q8kcrKgGX1iPtqy2pk8JO weZUId3426S/QBehCvQQ280GzEgkyKbO/8L+rt85CCPBPXkSW7Y9UYq3JSKzFaZnsQHi XB3g== 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=G4yjpqg1rAnA18mh0/EoXwqcDONKdK9GkPldrOAq/vE=; b=VpJbm7tM3qqUOXbbCQ68nu7OyeN8nkADmfCBkwFnYBzoIfGJOXJfE4E+xmyJledOQn x/3iwJ/PbQfE3/42MSDlvtF/pC5NWcVAiTr+ltYs8/p8ST9MxmGOML68SISGX0PRkHMt pjdCzKU+vdtS5a1xMVyxH3zCtbc1a6RUk+MJrjytK/rCCJTG9Rs7sjCsle/Kh43YF7uN UnRYNpNRtDLDCzgYYEfn84wIectEK6hh4JuTmbH9RbQ3mH/2hsDdVjWmVDXjyWMlM9ad aP/4MrfTZbiHsMI5aCnICoNthJDXKzuF2hY8IH4ACZ35VNS7eOH5LIXd9y0IKOOWslhq GhzQ== X-Gm-Message-State: AOAM532tseU/+Elr9eKQmOuUhSUfwMWFvs89vcJbZxzTH/DxrEj3hPbZ bB/Bi3ewRflymPVhaupu4vpaVugHMY1LqLVc X-Google-Smtp-Source: ABdhPJxXIsDuZqtw0TBT+z8Ec5SyICFndgPoflht4X/J4K5BwpyP8+atfg88cuGrkv24jYRbmIey2w== X-Received: by 2002:a63:d146:: with SMTP id c6mr16705852pgj.131.1618024347820; Fri, 09 Apr 2021 20:12:27 -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.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 20:12:27 -0700 (PDT) From: zheng qian To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Apr 2021 12:10:17 +0900 Message-Id: <20210410031017.1271-2-xqq@xqq.im> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210410031017.1271-1-xqq@xqq.im> References: <20210406081816.54105-1-xqq@xqq.im> <20210410031017.1271-1-xqq@xqq.im> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] libavformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption 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" Stream copy for arib_caption into mpegts is not working correctly for now. This patch utilizes the data stored in codecpar->extradata to write necessary stream_identifier_descriptor and data_component_descriptor into PMT table for arib_caption remuxing. This patch fixes the copying of arib_caption. After this patch, arib_caption inside the outputted (remuxed) mpegts stream can be recognized correctly as an arib_caption subtitle stream. Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index a357f3a6aa..e26a5d3b51 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -357,6 +357,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream *st) break; case AV_CODEC_ID_DVB_SUBTITLE: case AV_CODEC_ID_DVB_TELETEXT: + case AV_CODEC_ID_ARIB_CAPTION: stream_type = STREAM_TYPE_PRIVATE_DATA; break; case AV_CODEC_ID_SMPTE_KLV: @@ -714,8 +715,21 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } *len_ptr = q - len_ptr - 1; + } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) { + if (st->codecpar->extradata && st->codecpar->extradata_size >= 4) { + // stream_identifier_descriptor + *q++ = 0x52; // descriptor_tag + *q++ = 1; // descriptor_length + *q++ = st->codecpar->extradata[0]; // component_tag: stream_identifier + + // data_component_descriptor + *q++ = 0xFD; // descriptor_tag: ARIB data coding type descriptor + *q++ = 3; // descriptor_length + memcpy(q, &st->codecpar->extradata[1], 3); // data_component_id & additional_arib_caption_info + q += 3; + } } - break; + break; case AVMEDIA_TYPE_VIDEO: if (stream_type == STREAM_TYPE_VIDEO_DIRAC) { put_registration_descriptor(&q, MKTAG('d', 'r', 'a', 'c'));