# Dynamic Ads Insertion

**URL:** https://community.wowza.com/t/dynamic-ads-insertion/52629
**Category:** Wowza Developer Dojo
**Tags:** wowza-streaming-server-java-api
**Created:** [January 10, 2019, 4:38pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629 "2019-01-10T16:38:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Iyus\_Dedi\_Putra](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@Iyus\_Dedi\_Putra](https://community.wowza.com/u/Iyus_Dedi_Putra)
#### Post date: [January 10, 2019, 4:38pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/1 "2019-01-10T16:38:45Z")

</div>

Dear all,

I want to ask about how to get SCTE-35 markers on live streaming application. There is a documentation that we have to build java based code to get that file [Monitor MPEG-TS ingestion to process additional data streams (SCTE-35, KLV, etc.)](https://www.wowza.com/docs/how-to-monitor-mpeg-ts-ingestion-to-process-additional-data-streams-scte-35-klv-etc) .

```auto
import java.util.*;

import com.wowza.wms.amf.*;
import com.wowza.wms.logging.*;
import com.wowza.wms.rtp.model.*;
import com.wowza.wms.stream.*;
import com.wowza.wms.transport.mpeg2.*;
import com.wowza.wms.transport.mpeg2.ProgramMapTable.*;
import com.wowza.wms.transport.mpeg2.section.cue.*;

public class RTPDePacketizerMPEGTSMonitorCUE extends RTPDePacketizerMPEGTSNotifyBase
{
	private static final Class<RTPDePacketizerMPEGTSMonitorCUE> CLASS = RTPDePacketizerMPEGTSMonitorCUE.class;
	private static final String CLASSNAME = "RTPDePacketizerMPEGTSMonitorCUE";

	private IMediaStream stream = null;
	private RTPDePacketizerMPEGTS rtDePacketizerMPEGTS = null;
	private boolean isTimecodeReady = false;
	private RTPTrack rtpTrack = null;
	private boolean debugLog = false;

	class MPEGTSMonitorCUE implements IMPEG2UserMonitorSectionNotify
	{
		@Override
		public void onMonitorStart()
		{
		}

		@Override
		public void onMonitorStop()
		{
		}

		@Override
		public void onDataSection(int pid, AdaptationField field, MPEG2Section section)
		{
			if (section.getTableID() == SpliceInformationTable.SIT_TABLE_ID)
			{
				try
				{
					SpliceInformationTable spliceInformationTable = new SpliceInformationTable(section);
					if (spliceInformationTable != null)
					{
						if (debugLog)
							WMSLoggerFactory.getLogger(CLASS).info(CLASSNAME + ".onDataSection: " + spliceInformationTable.toString());

						SpliceInformationTableSerializeAMFContext serializeContext = new SpliceInformationTableSerializeAMFContext();

						serializeContext.timeReference = rtDePacketizerMPEGTS.getVideoTC();
						serializeContext.rtpTrack = rtpTrack;

						AMFDataObj amfData = spliceInformationTable.serializeAMF(serializeContext);
						if (amfData != null)
							stream.sendDirect("onCUE", amfData);
					}
				}
				catch(Exception e)
				{
					WMSLoggerFactory.getLogger(CLASS).error(CLASSNAME+".onDataSection: ", e);
				}
			}
		}
	}

	@Override
	public void onInit(RTPDePacketizerMPEGTS rtDePacketizerMPEGTS, RTPContext rtpContext, RTPDePacketizerItem rtpDePacketizerItem)
	{
		this.debugLog = rtDePacketizerMPEGTS.getProperties().getPropertyBoolean("rtpDePacketizerMPEGTSMonitorKLVDebugLog", this.debugLog);
	}

	@Override
	public void onStartup(RTPDePacketizerMPEGTS rtDePacketizerMPEGTS, RTPTrack rtpTrack)
	{
		WMSLoggerFactory.getLogger(CLASS).info(CLASSNAME+".onStartup");

		this.rtDePacketizerMPEGTS = rtDePacketizerMPEGTS;
		this.rtpTrack = rtpTrack;

		RTPStream rtpStream = rtpTrack.getRTPStream();
		if (rtpStream != null)
			this.stream = rtpStream.getStream();
	}

	@Override
	public void onTimecodeReady(RTPDePacketizerMPEGTS rtDePacketizerMPEGTS)
	{
		WMSLoggerFactory.getLogger(CLASS).info(CLASSNAME+".onTimecodeReady");

		this.isTimecodeReady = true;
	}

	@Override
	public void onPMT(RTPDePacketizerMPEGTS rtDePacketizerMPEGTS, ProgramMapTable newPMT)
	{
		WMSLoggerFactory.getLogger(CLASS).info(CLASSNAME+".onPMT");

		boolean SCTE35RegDescFound = false;

		ArrayList<Descriptor> regDescriptors = newPMT.programDescriptors.get(Descriptor.DESCRIPTOR_TAG_REGISTRATION);

		if (regDescriptors != null && regDescriptors.size() > 0)
		{
			for (Descriptor desc : regDescriptors)
			{
				SCTE35RegDescFound |= ((RegistrationDescriptor)desc).formatIdentifier == RegistrationDescriptor.REG_IDENTIFICATION_SCTE_SPLICE_FORMAT;
			}
		}

		for (StreamInfo s : newPMT.streams.values())
		{
			if (SCTE35RegDescFound)
			{
				ArrayList<Descriptor> descriptors = null;

				if (descriptors == null)
					descriptors = s.descriptors.get(Descriptor.DESCRIPTOR_TAG_CUE_IDENTIFIER);

				if (descriptors == null)
					descriptors = s.descriptors.get(Descriptor.DESCRIPTOR_TAG_STREAM_IDENTIFIER);

				if (descriptors != null)
				{
					WMSLoggerFactory.getLogger(CLASS).info(CLASSNAME+".onPMT: Hit cue point PID: 0x"+Integer.toHexString(s.PID));

					if (!rtDePacketizerMPEGTS.containsPIDMonitorMap(s.PID))
					{
						rtDePacketizerMPEGTS.putPIDMonitorMap(s.PID, new MPEGTSMonitorCUE());
					}
				}
			}
		}
	}
}

```

The code example above as MPEG-TS listener and PID monitor for processing ad markers and inserting the onCUE AMF data event into the stream with the ad marker data.

The are some question i want to know about

- Where do put that code? do have to compile it become jar file?
- Do i still need to setup [Use generic Stream Target API to prepare Apple HLS streams for ad insertion (SCTE-35)](https://www.wowza.com/docs/how-to-use-generic-stream-target-api-to-prepare-apple-hls-streams-for-ad-insertion-scte-35) because our vendor just need to get the SCTE-35 markers.
- Do i need to put that code on all our wowza server?

note : our topology is camera --\> encoder --\> transcoder(ffmpeg) + wowza origin --\> edge server.

---

<div class="post-metadata">

### Author: ![Hieu\_Le](https://avatars.discourse-cdn.com/v4/letter/h/d2c977/32.png) [@Hieu\_Le](https://community.wowza.com/u/Hieu_Le)
#### Post date: [January 16, 2019, 4:38pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/2 "2019-01-16T16:38:28Z")

</div>

- Where do put that code? do have to compile it become jar file?

> Compile into a jar file and put under lib folder of Wowza, then configure the application to load that module, refer the guideline

- Do i still need to setup

> Setup Stream Target to output to UDP (MPEG-TS)

- Do i need to put that code on all our wowza server?

> Only on the server that processing the stream and insert the SCTE-35 marker, then output to MPEG-TS (UDP)

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [January 16, 2019, 4:43pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/3 "2019-01-16T16:43:01Z")

</div>

Checking with engineers this morning- will respond shortly. Thank you for your patience.

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [January 16, 2019, 8:52pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/4 "2019-01-16T20:52:38Z")

</div>

If you want to use the ‘RTPDePacketizerMPEGTSMonitorCUE’, unchanged, then there is a version that is included, so you don’t need to compile the example one. The name is `com.wowza.wms.rtp.depacketizer.RTPDePacketizerMPEGTSMonitorCUE`.

For HLS playback using splice markers, you do need to compile the Stream target code, but if you want to do something else with the data then you will need to use your own code. You would need to enable the depacketizer monitor on each server that is ingesting SCTE-35.

If you would like additional assistance setting up this workflow, you can post in our Hire a Consultant Forum or reach out in a support ticket if you receive error codes. Thanks.

---

<div class="post-metadata">

### Author: ![Iyus\_Dedi\_Putra](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@Iyus\_Dedi\_Putra](https://community.wowza.com/u/Iyus_Dedi_Putra)
#### Post date: [January 17, 2019, 5:04pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/5 "2019-01-17T17:04:48Z")

</div>

[@Rose Power-Wowza Community Manager](http://community.wowza.com/community/questions/50310/dynamic-ads-insertion.html?childToView=50384#),

we don’t want to do anything else with the data stream, so for our needs with need to setup and compile the java code an put it on our edge server, isn’t it? [how-to-use-generic-stream-target-api-to-prepare-apple-hls-streams-for-ad-insertion-scte-35](https://www.wowza.com/docs/how-to-use-generic-stream-target-api-to-prepare-apple-hls-streams-for-ad-insertion-scte-35)

---

<div class="post-metadata">

### Author: ![Iyus\_Dedi\_Putra](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@Iyus\_Dedi\_Putra](https://community.wowza.com/u/Iyus_Dedi_Putra)
#### Post date: [January 17, 2019, 5:04pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/6 "2019-01-17T17:04:54Z")

</div>

[@Rose Power-Wowza Community Manager](http://community.wowza.com/community/questions/50310/dynamic-ads-insertion.html?childToView=50384#),

we don’t want to do anything else with the data stream, so for our needs with need to setup and compile the java code an put it on our edge server, isn’t it? [how-to-use-generic-stream-target-api-to-prepare-apple-hls-streams-for-ad-insertion-scte-35](https://www.wowza.com/docs/how-to-use-generic-stream-target-api-to-prepare-apple-hls-streams-for-ad-insertion-scte-35)

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [January 17, 2019, 5:51pm UTC](https://community.wowza.com/t/dynamic-ads-insertion/52629/7 "2019-01-17T17:51:27Z")

</div>

Hello @Iyus Dedi Putra, thank you for that information. The engineers our requesting you submit a support ticket so they can take a closer look at it and walk you through the steps. They only do this through support tickets and not in the forums for tracking purposes and to properly run tests for you. This is the quickest way to make sure you have it setup correctly. They will looking for your ticket here:

[https://www.wowza.com/support/open-ticket](https://www.wowza.com/support/open-ticket)

Thanks and our engineers will help you with the proper configuration.
