From patchwork Thu Apr 22 12:03:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zheng qian X-Patchwork-Id: 27209 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp515569iob; Thu, 22 Apr 2021 05:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvK2+Od1X/+PZdVbCpe1yPIrnkPq5KWLlFEJubOuIcfhs6q4ADmxSKTuvp1Y/kuDIpFavs X-Received: by 2002:a17:906:9407:: with SMTP id q7mr2999523ejx.434.1619093346474; Thu, 22 Apr 2021 05:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619093346; cv=none; d=google.com; s=arc-20160816; b=ExNzloyTN7hP6/sf5Wej391l9+ZFRw+WORzHxlJz5zBAEz8GVM8FRy/5L70gA86nPn IY1OMH4XxD+Ca6yLB1bxEJ9Bxqy2hXwIcMKEwEhGpTsbj2805XqwLNqcqK4E291j3e25 L8c3ibBoaPIVlTA0SCM7q0x0a8SpscTEvZBbbAhQQDTKlXCn5qxKasG97OngS+RS11w5 ezUFrmpR/4m0TZqbhJFr10+xdwI8cDKoKxx9K5tSt7M4kvzoxCi/ctCNVHinPMzufUAs eMyY9cWl2i7T28kAOI4fmUtwOrdQUz+YSQ/+LBjuJ+MH3X3792sagbInwyxezDtODaQ3 hFzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Neb5IO+4bbuoJMp6D0OP5iBgEHbcFzASn7QCaXmamsA=; b=ZNv9Uqsmalfq68TkR8f/rR+kKhMwtvvgSqAQsqdoPJwtt94og4kqBK+YHAq+vdoPZO ndy3+Kq0RpCRNK82W1Qc8p6L1gMAfldVO8XRYhxNzWl013TlohavofxOb33srpbD6xHL DvdZ+I259J8cl8yrm1Zu+QQGNzmOAOyFcqkoAt+4Az5rRjUrEF1zc4ZdwoXqNulQaSqI y0SQ/j65wHZwvdBp4Xa2qs1m5DsApz+c+JWQugIEBh5tCNMbtuUgyXrHq75GdHgLv4Nd vjM86DWNnf2FXQUFaf0V2trKnQ+PvXQ9vn8eKqeqakFVX8PKm4vQ54ZvNAT/sD3MHQhj TQOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@xqq-im.20150623.gappssmtp.com header.s=20150623 header.b=iDczLKgs; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e1si2144209ejq.139.2021.04.22.05.09.05; Thu, 22 Apr 2021 05:09:06 -0700 (PDT) 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=@xqq-im.20150623.gappssmtp.com header.s=20150623 header.b=iDczLKgs; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B310C689DC4; Thu, 22 Apr 2021 15:09:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 674366899EF for ; Thu, 22 Apr 2021 15:08:55 +0300 (EEST) Received: by mail-pf1-f182.google.com with SMTP id i190so31520796pfc.12 for ; Thu, 22 Apr 2021 05:08:55 -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=pyY5MHstAcJBfi68XG68o29sJAYi8uiwwPtAUIHLoCw=; b=iDczLKgsIEaM1TuaSk7ppro6WacRW3axJ6NSZ6aFLQJTWBqx4uf/xvQxg9fiyWkwnt t77eiAQA/yNL6G4fDgYwqRZW+/V6QUq5jpDFGK4qatn2Qdjh22grMRWtw8cNbu0qaj6Z 09Pa/Mdoc2UxMk0IgNij5CGkFyxJMf5ZFpF2B7DgmYIAVFPcOMz86k0u5fF2CnEVtGxl d2HY9CInuFoqBQW08OdlGFyMidAJXSMK4LHyo2t1sTeqvmtgtBuYnhNtCY3hrJ7CdUg7 eQ/7VgxX4YBwTj7rxRPrlL+6NiDPh+A6WfSp5sFgS1MTdTk4tge5W6TCbi7J5PJurz5V nS+g== 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=pyY5MHstAcJBfi68XG68o29sJAYi8uiwwPtAUIHLoCw=; b=TNAWiBcKeRcM1oVCCE0/xsR1ZlBtFWl+uqjNsU998At2adITcCk29H7QcjG8wlnLvd 3VhXT/YnyAW+A9jrTA0XziIvp5K85FzkNCaVt6cGsn9wT4f/cdwsfa0lQ8ZJj2YQyhb4 eFI12lhWkF4yFN8tuk7Pp7qUw3To0qgXuXzzktzkMFtkXYRZ+unqPpmcIUvWqdUfodUT xifJhXrdmNNCxO004MMEWmUUxNhMZuG4IibJok4xuebk38fCU5avI/BM1iiQm4O7KTsc 67WmsGjC6H5LF3o5smwWoJopIf8zh72mPuc8NrpvuhECrCYlA6ylcjHRKRXt9S+fKlax Gzcg== X-Gm-Message-State: AOAM533KZOVnhh/UvTfOmIMgvCYL3il/LKT2RV8vZMdzqFzF00bs1IYp ANRC0PMg3rkuXF/bBDucBZ9ZTNSg0wUdirat X-Received: by 2002:a17:902:8697:b029:ea:a5dc:925f with SMTP id g23-20020a1709028697b02900eaa5dc925fmr3410886plo.56.1619093013732; Thu, 22 Apr 2021 05:03:33 -0700 (PDT) Received: from zhengqian-xps.lan (ngn-nat1.v4.open.ad.jp. [202.222.12.138]) by smtp.gmail.com with ESMTPSA id l3sm4787667pju.44.2021.04.22.05.03.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Apr 2021 05:03:30 -0700 (PDT) From: zheng qian To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Apr 2021 21:03:09 +0900 Message-Id: <20210422120311.10294-1-xqq@xqq.im> X-Mailer: git-send-email 2.29.2 In-Reply-To: <1245c8f2-93d4-6153-68d8-2351fab30cd4@gmail.com> References: <1245c8f2-93d4-6153-68d8-2351fab30cd4@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types 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 Cc: zheng qian Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kN3iKkwP9e6i Changes since v2: Fix PES_packet_length mismatch bug According to the PES packet definition defined in Table 2-17 of ISO_IEC_13818-1 specification, some fields like PTS/DTS or pes_extension could only appears if the stream_id meets the condition: if (stream_id != 0xBC && // program_stream_map stream_id != 0xBE && // padding_stream stream_id != 0xBF && // private_stream_2 stream_id != 0xF0 && // ECM stream_id != 0xF1 && // EMM stream_id != 0xFF && // program_stream_directory stream_id != 0xF2 && // DSMCC_stream stream_id != 0xF8) // ITU-T Rec. H.222.1 type E stream And the following stream_id types don't have fields like PTS/DTS: else if ( stream_id == program_stream_map || stream_id == private_stream_2 || stream_id == ECM || stream_id == EMM || stream_id == program_stream_directory || stream_id == DSMCC_stream || stream_id == ITU-T Rec. H.222.1 type E stream ) { for (i = 0; i < PES_packet_length; i++) { PES_packet_data_byte } } Current implementation skipped the judgement of stream_id causing some kind of stream like private_stream_2 to be incorrectly written with PTS/DTS field. For example, Japan DTV transmits news and alerts through ARIB superimpose that utilizes private_stream_2 still could not be remuxed correctly for now. This patch set fixes the remuxing for private_stream_2 and other stream_id types. Signed-off-by: zheng qian --- libavformat/mpegtsenc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index f302af84ff..b59dab5174 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1476,6 +1476,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } } header_len = 0; + + if (stream_id != 0xBC && // program_stream_map + stream_id != 0xBE && // padding_stream + stream_id != 0xBF && // private_stream_2 + stream_id != 0xF0 && // ECM + stream_id != 0xF1 && // EMM + stream_id != 0xFF && // program_stream_directory + stream_id != 0xF2 && // DSMCC_stream + stream_id != 0xF8) { // ITU-T Rec. H.222.1 type E stream + flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; @@ -1569,6 +1579,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; } + } else { + len = payload_size; + *q++ = len >> 8; + *q++ = len; + } is_start = 0; } /* header size */