From patchwork Wed May 22 15:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_H=C3=A5kon?= X-Patchwork-Id: 13250 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 58377447E22 for ; Wed, 22 May 2019 18:04:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 33813689A23; Wed, 22 May 2019 18:04:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40136.protonmail.ch (mail-40136.protonmail.ch [185.70.40.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37C2468050E for ; Wed, 22 May 2019 18:04:36 +0300 (EEST) Date: Wed, 22 May 2019 15:04:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1558537474; bh=8QZF8FK758q/Uyx++o6rs0B26hgN3uUja2FPSnYvrIk=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=mf8lwYDrsO+WgsZn9UeroefAa4FAGVKsk2JCT1cRkWxwihv4aJSez0HnuMWFHNA8x 7yZOd2M6Mj8r48/DFCRf3FUdx09Vv9vEUyLy0yoBlZIAHBCCH1czEWOxEaVI4LBGJb GRYcrWjLfkyShnZdqVyNgaFiJQVvISr5PnnBbz40= To: FFmpeg development discussions and patches From: =?UTF-8?Q?Andreas_H=C3=A5kon?= Message-ID: Feedback-ID: Mx8CaiV20jk_fqXDN0fFpg3vRaGkb9VCTrYRnZNHwEija3aOdqvFspzl6ODkmHrlSKJSx29p-LzkuvS_96L02A==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc: adaptive alignment for teletext PES packets 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi, Patch to generate aligned Teletext PES packets using the MPEG-TS muxer when the TS header contains data. Regards. A.H. --- From 5b476153e0fcced53afa1b77543c2e386f08c504 Mon Sep 17 00:00:00 2001 From: Andreas Hakon Date: Wed, 22 May 2019 15:36:50 +0100 Subject: [PATCH] libavformat/mpegtsenc: adaptive alignment for teletext PES packets The code that generates the PES packets for Teletext data aligns the PES packets with the boundaries of the TS packets. The strategy used is to insert padding stuff into the PES header. The size of this padding alignment currently has a fixed size of 36 bytes. And this value is correct when all of the Teletext TS packets have payload only. However, inserting some data into the TS header breaks this assumption. In this case, the Teletext PES packets are not aligned and the end of the PES packet is inserted into an additional TS packet with a large amount of TS padding. This patch calculates the size of the TS header in order to reduce the size of the PES padding and thus accommodate the PES packet to the TS boundaries. In this way no additional TS packets are produced. Signed-off-by: Andreas Hakon libavformat/mpegtsenc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 1.7.10.4 diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index fc0ea22..f1772ac 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1328,8 +1328,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, header_len += 3; } if (is_dvb_teletext) { - pes_header_stuffing_bytes = 0x24 - header_len; - header_len = 0x24; + int header_stuff = (get_ts_payload_start(buf) - buf) - 4; + if (header_stuff - header_len > 0x24) + header_stuff = 0; + pes_header_stuffing_bytes = 0x24 - header_len - header_stuff; + header_len = 0x24 - header_stuff; } len = payload_size + header_len + 3; /* 3 extra bytes should be added to DVB subtitle payload: 0x20 0x00 at the beginning and trailing 0xff */