From patchwork Mon Jan 13 18:17:26 2020 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: 17326 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 C897644A1E6 for ; Mon, 13 Jan 2020 20:17:42 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 828D668AD52; Mon, 13 Jan 2020 20:17:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40132.protonmail.ch (mail-40132.protonmail.ch [185.70.40.132]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 27FEA68A8A5 for ; Mon, 13 Jan 2020 20:17:36 +0200 (EET) Date: Mon, 13 Jan 2020 18:17:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1578939454; bh=UIiLvB6Le6AdRy990r/hcoOeUOOgA6SUeXqoOiVrtrM=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=qFxb8z76BP0UKg1BSjKAk8Qw/i/0Lyel9QtIMXvHTE6vP3nnyQ2lJoEW0i7XLc/Sd vsnYJ1K7y4MdAREAHh3uNnAfjyjI20+v7y01uHKmq7UYANpAmbmecgkX7coPH4kRn4 tXFYF7xs6Lsq2EqAsUQd8BGpQDwRAG8QO0EF1pd0= 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=2.8 required=7.0 tests=ALL_TRUSTED,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HTML_MESSAGE shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: ** 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: splice count [WIP] 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" This patch is Work-In-Progess, and I need your help... The objective of this patch is to insert the Splicing Point Count data inside the MPEG-TS header. The current code does it for every video packet. But this is buggy as we need to insert this data at GOP boundaries. Then the code is prepared to use the vars 'is_start_gop' and 'is_end_gop'. But we need to complete it with two functions that get these data from the pkt of from the bitstream. Please, can you help me to complete it? Thank you! --- A.H. From 54cfa26b83110bbd71d41fb9729828291dbfc873 Mon Sep 17 00:00:00 2001 From: Andreas Hakon Date: Mon, 13 Jun 2020 19:11:00 +0100 Subject: [PATCH] libavformat/mpegtsenc: splice count [WIP] This patch is Work-In-Progess, and I need your help... The objective of this patch is to insert the Splicing Point Count data inside the MPEG-TS header. The current code does it for every video packet. But this is buggy as we need to insert this data at GOP boundaries. Then the code is prepared to use the vars 'is_start_gop' and 'is_end_gop'. But we need to complete it with two functions that get these data from the pkt of from the bitstream. Please, can you help me to complete it? Thank you! Signed-off-by: Andreas Hakon --- libavformat/mpegtsenc.c | 23 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 0 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index ccb631d746..00647a6750 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1162,6 +1162,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, uint8_t buf[TS_PACKET_SIZE]; uint8_t *q; int val, is_start, len, header_len, write_pcr, is_dvb_subtitle, is_dvb_teletext, flags; + int splice, is_start_gop, is_end_gop; int afc_len, stuffing_len; int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; @@ -1266,6 +1267,28 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, extend_af(buf, write_pcr_bits(q, pcr)); q = get_ts_payload_start(buf); } + /* Set the Splicing Point Count */ + /* http://www.mpeg.org/MPEG/splicing-FAQ.html */ + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + is_start_gop = 1; // TODO: Get if this is the first PES packet of a GOP + is_end_gop = 1; // TODO: Get if this is the last PES packet of the GOP + + if (is_start && is_start_gop) + splice = -1; + else if (is_end_gop && payload_size < TS_PACKET_SIZE * 127) + splice = payload_size / TS_PACKET_SIZE; + else + splice = 127; + + if (splice <= 5) { + av_log(s, AV_LOG_TRACE, "Splicing Point Count to %i\n", splice); + set_af_flag(buf, 0x04); + q = get_ts_payload_start(buf); + extend_af(buf, 1); + *q++ = splice; + q = get_ts_payload_start(buf); + } + } if (is_start) { int pes_extension = 0; int pes_header_stuffing_bytes = 0;