@@ -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;