# List chunks on an HLS live stream

**URL:** <https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [June 6, 2014, 9:09pm UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084 "2014-06-06T21:09:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steffen\_Christensen](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Steffen\_Christensen](https://community.wowza.com/u/Steffen_Christensen)\
**Post date:** [June 6, 2014, 9:09pm UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/1 "2014-06-06T21:09:31Z")

</div>

Hey guys,

Is there a way to list chunks on a HLS/cupertino live stream?

===

I have a concrete need where my player will need to know exactly when the live stream is taking place (slide sync, of course). All of this is fairly approachable if only I can build an index up of the chunks along with a timestamp.

Obviously, I’ve been playing around in order to get there, but listening to events on the packetizer and the media list renditions isn’t really doing the trick – and at the same time the packetizer seems to be teasing me by writing the exact info that I need to the log file:

2014-06-06\_19:55:13.09204 INFO server comment - LiveStreamPacketizerCupertino.endChunkTS[live/_definst_/dev-3753984-ab701201ab4621b3454b.mp4]: Add chunk: id:11 mode:TS[H264,AAC] a/v/k:151/306/3 duration:10566

… and I’d love to get this directly from Wowza instead of parsing log files 😉

---

<div class="post-metadata">

**Author:** ![Steffen\_Christensen](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Steffen\_Christensen](https://community.wowza.com/u/Steffen_Christensen)\
**Post date:** [June 15, 2014, 2:35pm UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/2 "2014-06-15T14:35:06Z")

</div>

Sorry to push on this one, but does anyone have a good idea? Any events being fired when chunks are created, even if they are private APIs designed to be used only by DVR…?

---

<div class="post-metadata">

**Author:** ![Steffen\_Christensen](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Steffen\_Christensen](https://community.wowza.com/u/Steffen_Christensen)\
**Post date:** [June 18, 2014, 11:57am UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/3 "2014-06-18T11:57:39Z")

</div>

Thanks Matt – but aren’t these events fired when the chunks are requested, not when there’s generated? If so, the timing would be off with this scheme?

---

<div class="post-metadata">

**Author:** ![Steffen\_Christensen](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Steffen\_Christensen](https://community.wowza.com/u/Steffen_Christensen)\
**Post date:** [June 22, 2014, 9:59pm UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/4 "2014-06-22T21:59:31Z")

</div>

Following up on this, the release notes for 4.0.4 state that:

- Added support to Apple HLS (cupertino) live stream packetizer to provide a IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler class to control how chunks are numbered

- LiveStreamPacketizerCupertino.setChunkIdHandler(IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHan dler chunkIdHandler)

- Added LiveStreamPacketizers/Properties string property cupertinoChunkIdHandlerClass to specify full Java path to a class that implements IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler to control how cupertino chunks are numbered

- Added IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler interface to control how cupertino chunks are numbered

- void init(LiveStreamPacketizerCupertino liveStreamPacketizer);

- long onAssignChunkId(HTTPStreamerCupertinoLiveStreamPacketizerChunkIdContext chunkIdContext);

This in turn is a way of saying that there’s now an interface to handle which number is assigned to an HLS chunk (which were previously just number sequentially). Matt notes that this can be controlled by a property in settings, but it’s also fairly easy to do programatically (and I wanted to keep my module structure).

My code to number chunks by the epoch time in milliseconds of their creation looks like this:

> import com.wowza.wms.module.\*;
> 
> import com.wowza.wms.application.\*;
> 
> import com.wowza.wms.httpstreamer.cupertinostreaming.livestreampacketizer.\*;
> 
> import com.wowza.wms.stream.livepacketizer.\*;
> 
> public class MyWowzaModule extends ModuleBase {
> 
> public void onAppStart(IApplicationInstance appInstance) {
> 
> // We want to set chunk numbers for cupertino streaming; this is done first by listening to the live stream packetizers
> 
> appInstance.addLiveStreamPacketizerListener(new LiveActionNotify(appInstance));
> 
> }
> 
> /\*\*\* CHUNK NUMBER HANDLING
> 
> Set chunk numbers by the epoch time (in milliseconds) of their creation
> 
> \*\*\*/
> 
> class CupertinoChunkIdHandler implements IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler {
> 
> public void init(LiveStreamPacketizerCupertino liveStreamPacketizer) {}
> 
> public long onAssignChunkId(HTTPStreamerCupertinoLiveStreamPacketizerChunkIdContext chunkIdContext) {
> 
> return System.currentTimeMillis();
> 
> }
> 
> }
> 
> class LiveActionNotify implements ILiveStreamPacketizerActionNotify {
> 
> public LiveActionNotify(IApplicationInstance appInstance) {}
> 
> public void onLiveStreamPacketizerCreate(ILiveStreamPacketizer liveStreamPacketizer, String streamName) {}
> 
> public void onLiveStreamPacketizerDestroy(ILiveStreamPacketizer liveStreamPacketizer) {}
> 
> public void onLiveStreamPacketizerInit(ILiveStreamPacketizer liveStreamPacketizer, String streamName) {
> 
> while(true) {
> 
> if (!(liveStreamPacketizer instanceof LiveStreamPacketizerCupertino)) break;
> 
> LiveStreamPacketizerCupertino cupertinoPacketizer = (LiveStreamPacketizerCupertino)liveStreamPacketizer;
> 
> cupertinoPacketizer.setChunkIdHandler(new CupertinoChunkIdHandler());
> 
> break;
> 
> }
> 
> }
> 
> }
> 
> }

This is awesome. It really is.

More wants more though: Is there any ways to do the same thing for DVR chunks?

---

<div class="post-metadata">

**Author:** ![Roger\_Littin1](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@Roger\_Littin1](https://community.wowza.com/u/Roger_Littin1)\
**Post date:** [June 23, 2014, 9:33am UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/5 "2014-06-23T09:33:28Z")

</div>

Hi,

Even though you code will create chunks with incrementing id numbers, it may possibly cause problems on playback. THe HLS specification says that the segment ids must be sequential and increment by 1 each time. You would have to return **system time / target duration** to get this.

See [http://tools.ietf.org/html/draft-pantos-http-live-streaming-13](http://tools.ietf.org/html/draft-pantos-http-live-streaming-13) for details.

Roger.

---

<div class="post-metadata">

**Author:** ![Matt\_Young](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/matt_young/32/389_2.png) [@Matt\_Young](https://community.wowza.com/u/Matt_Young)\
**Post date:** [June 16, 2014, 3:23am UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/6 "2014-06-16T03:23:51Z")

</div>

You might be able to obtain what you are looking for using IVHostHTTPStreamerRequestValidator and the validateHTTPStreamerRequest event.

---

<div class="post-metadata">

**Author:** ![Matt\_Young](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/matt_young/32/389_2.png) [@Matt\_Young](https://community.wowza.com/u/Matt_Young)\
**Post date:** [June 19, 2014, 4:20am UTC](https://community.wowza.com/t/list-chunks-on-an-hls-live-stream/34084/7 "2014-06-19T04:20:06Z")

</div>

In 4.0.4 (latest release) we do have IHTTPStreamerCupertinoLiveStreamPacketizerChunkIdHandler interface that implements the init and onAssignChunkId events which may correlate more closely to what you are looking to do. You can create a class that implements this interface then define the handler in your Application.xml within the LiveStreamPacketizers/Properties to turn it on as follows:

```auto
<Property>
                <Name>cupertinoChunkIdHandlerClass</Name>
                <Value>[Class-Path]</Value>
</Property>

```
