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 */ From patchwork Tue Apr 6 08:18: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: 26778 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 829D5449B3D for ; Tue, 6 Apr 2021 11:45:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6493F68A3C3; Tue, 6 Apr 2021 11:45:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 63CF2689E29 for ; Tue, 6 Apr 2021 11:45:43 +0300 (EEST) Received: by mail-pl1-f176.google.com with SMTP id l1so7081837plg.12 for ; Tue, 06 Apr 2021 01:45:43 -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=SJ8BBjCKsZCpogQbjaGY1chXKMxA9gT/zvaQUUjFwbvFD/axSt1OxCYqNBrdKC3AOd +cjv/sAn9YnWXugm2InywCiwyZK4CtOXmrQxh3ELhPHfKxc0zbLk+YKPbO9c6x6U2GIG NSMZ/RlFqHaUDxGhb4NPmeVDJpyuvoIeS8E4xRvuO5Juu4ot2NwkVkDwIs3DBP83GguU AZFTUo6CvEce43i2NCP4juoxzD/Z1QIGw9he2dp+Ok3uZZrJTP4FhYTyt+PsTwTNWOYJ s70306IBvKWlUok1mct8wQDi4svbnULC2Skvl6jVyq9ECYRzqvybHH91MHlq7jjq3L3F yHLQ== 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=RO6ntyt0yv7Ksni/WKryOVKdIeD8bg5AtnK6Ar+Onm59gqeY8r9SVrVwugHrAmGOrw Obs0O9+JF/KIkAPsMPcCbf8/B76Eo8PoOLryK3YBA3fSF5mL63j1P39ZMuHwmNYOofA7 ijqcKePTg5wSV1+C8aM5rcvZFQ6T4Dz67gvSraJkGLbuc7kYM6BtMa1NqAvtdaYhTUbH hGhVm+15Htb1FQpkFq6ZKv+3dfiZUZsi8qxsZtLV6EzsciqJoUOVrWWykoNBDznC0ZAX LOLZAao2mdOa4kpukaaZ8smgsVh8D0soAsOWffDWx7JOXny8nTIXZ8D22eUWFwNtvIMm w1qA== X-Gm-Message-State: AOAM532W50KPe9Ol7TUJGeozupvWC2swh60S3PnATSF8QYUz442rrr3U dhGkusG+zEcjL3QuoO0Cqh0G/8gEcY7Yf0rt X-Google-Smtp-Source: ABdhPJyZ9LU/sznFPujRRne+uZiYBmqTIsTUnbSKeYUjcnoBfFNnXeF18bwsf+tt9bScSz67My/y/g== X-Received: by 2002:aa7:8097:0:b029:229:83ec:cac0 with SMTP id v23-20020aa780970000b029022983eccac0mr26513869pff.67.1617697169590; Tue, 06 Apr 2021 01:19:29 -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.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Apr 2021 01:19:29 -0700 (PDT) From: zheng qian To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Apr 2021 17:18:16 +0900 Message-Id: <20210406081816.54105-2-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 v1 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 , jeebjp@gmail.com 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'));