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 <andreas.ha...@protonmail.com>
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 <andreas.ha...@protonmail.com>
---
 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;
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to