|
1 | | -# wse-plugin-interstitials-rest-api |
| 1 | +# Wowza Streaming Engine HLS interstitials REST API |
| 2 | + |
| 3 | +With the **HLS Interstitials REST API** module for [Wowza Streaming Engine™ media server software](https://www.wowza.com/products/streaming-engine), you can use a REST API to add HLS interstitials to a live video feed by inserting an `#EXT-DATE-RANGE` tag in the HLS manifest. |
| 4 | + |
| 5 | +For more details about HLS interstitials, see [Getting Started with HLS Interstitials](https://developer.apple.com/streaming/GettingStartedWithHLSInterstitials.pdf). |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +* Wowza Streaming Engine™ 4.9.4 or later is required |
| 10 | +* Java 21 |
| 11 | +* Gradle (to build) |
| 12 | + |
| 13 | +## Build instructions |
| 14 | + |
| 15 | +1. Clone this repository to your local filesystem. |
| 16 | +2. Update the `wseLibDir` variable in the `gradle.properties` file to point to the local Wowza Streaming Engine `lib` folder. |
| 17 | +3. Run `./gradlew build` to build the jar file. |
| 18 | + |
| 19 | +## Install |
| 20 | + |
| 21 | +1. Copy `wse-plugin-cloud-interstitials-rest-api-x.x.x.jar` into the `lib` directory. |
| 22 | +2. Add the HTTPProvider to `VHost.xml`: |
| 23 | + |
| 24 | +```xml |
| 25 | +<HTTPProvider> |
| 26 | + <BaseClass>com.wowza.wms.plugin.interstitialsrestapi.http.HTTPProviderInterstitialsRestApi</BaseClass> |
| 27 | + <RequestFilters>v1/interstitials/*</RequestFilters> |
| 28 | + <AuthenticationMethod>none</AuthenticationMethod> |
| 29 | +</HTTPProvider> |
| 30 | +``` |
| 31 | + |
| 32 | +3. Add the following property to `VHost.xml`: |
| 33 | + |
| 34 | +```xml |
| 35 | +<Property> |
| 36 | + <Name>optionsCORSHeadersAddMain</Name> |
| 37 | + <Value>Access-Control-Allow-Methods:DELETE</Value> |
| 38 | + <Type>String</Type> |
| 39 | +</Property> |
| 40 | +``` |
| 41 | + |
| 42 | +4. Add the following module to the Application.xml: |
| 43 | + |
| 44 | +```xml |
| 45 | +<Module> |
| 46 | + <Name>ModuleInterstitialsRestApi</Name> |
| 47 | + <Description>ModuleInterstitialsRestApi</Description> |
| 48 | + <Class>com.wowza.wms.plugin.interstitialsrestapi.module.ModuleInterstitialsRestApi</Class> |
| 49 | +</Module> |
| 50 | +``` |
| 51 | + |
| 52 | +5. Add the following property to the `HTTPStreamer > Properties` block in the Application.xml file: |
| 53 | + |
| 54 | +```xml |
| 55 | +<Property> |
| 56 | + <Name>cupertinoEnableProgramDateTime</Name> |
| 57 | + <Value>true</Value> |
| 58 | + <Type>Boolean</Type> |
| 59 | +</Property> |
| 60 | +``` |
| 61 | + |
| 62 | +## API details |
| 63 | + |
| 64 | +### API pattern |
| 65 | + |
| 66 | +* `/v1/interstitials/applications/{appName}/streams/{streamName}` |
| 67 | + |
| 68 | +### API supported methods |
| 69 | + |
| 70 | +* `POST` |
| 71 | +* `DELETE` |
| 72 | + |
| 73 | +### Metadata |
| 74 | + |
| 75 | +A JSON object can be passed into the video stream using the properties outlined in the following table. |
| 76 | + |
| 77 | +#### Properties |
| 78 | + |
| 79 | +| Property | Description | |
| 80 | +| :-------------- | :----------------------------------------------------------------------- | |
| 81 | +| `id` | Specify an identifier to use for the ad. Default value is `ad1`. | |
| 82 | +| `start_date` | Define an absolute start date in ISO8601 format, or +seconds from now. Defaults to the current time. | |
| 83 | +| `duration` | Specify duration for the ad. Default value is 30 seconds. | |
| 84 | +| `asset_list` | Define a URL for an assets list. If not defined, must have `asset_uri`. | |
| 85 | +| `asset_uri` | Define a URL for a single asset. If not defined, must have `asset_list`. | |
| 86 | +| `resume_offset` | Determine when primary playback should resume following the playback of the interstitial. Default value is 0 seconds. | |
| 87 | +| `restrict` | Create a list of navigation restrictions. Default value is `SKIP,JUMP`. | |
| 88 | + |
| 89 | +## Examples and demo |
| 90 | + |
| 91 | +After building the module, start Wowza Streaming Engine and Wowza Streaming Engine Manager using the docker-compose.yaml file in this repository. It includes a pre-configured Wowza Streaming Engine instance and sample `live` and `simu-live` applications. |
| 92 | + |
| 93 | +1. Run the following command: |
| 94 | + |
| 95 | +```bash |
| 96 | +docker compose up |
| 97 | +``` |
| 98 | + |
| 99 | +2. Insert an HLS interstitial for the `simu-live` application with a 10 second ad break, five seconds from now: |
| 100 | + |
| 101 | +```shell |
| 102 | +curl -X POST -H "Content-Type: application/json" -d '{ |
| 103 | + "id": "ad1", |
| 104 | + "start_date": "+5", |
| 105 | + "duration": 10.0, |
| 106 | + "asset_uri": "https://wv-cdn-00-00.flowplayer.com/7bb18344-08f9-4c1e-84a7-80c1007aa99b/cmaf/6089d839-d699-424b-b914-445152e25115/playlist.m3u8" |
| 107 | + }' http://localhost/v1/interstitials/applications/simu-live/streams/myStream |
| 108 | +``` |
| 109 | + |
| 110 | +3. To test playback, go to: |
| 111 | + |
| 112 | +```text |
| 113 | +https://hlsjs.video-dev.org/demo/?src=https://wse-trial.wowza.com/simu-live/myStream/playlist.m3u8 |
| 114 | +``` |
| 115 | + |
| 116 | +4. To view the HLS interstitial in the HLS manifest, run: |
| 117 | + |
| 118 | +```bash |
| 119 | +curl http://localhost/simu-live/myStream/chunklist_w2003968828.m3u8 |
| 120 | +``` |
| 121 | + |
| 122 | +## HLS output example |
| 123 | + |
| 124 | +An HLS output example looks similar to: |
| 125 | + |
| 126 | +```text |
| 127 | +#EXTM3U |
| 128 | +#EXT-X-VERSION:3 |
| 129 | +#EXT-X-TARGETDURATION:4 |
| 130 | +#EXT-X-MEDIA-SEQUENCE:60897 |
| 131 | +#EXT-X-DISCONTINUITY-SEQUENCE:0 |
| 132 | +#EXT-X-PROGRAM-DATE-TIME:2025-02-13T17:03:19.368Z |
| 133 | +#EXT-X-DATERANGE:ID="ad1-5",CLASS="com.apple.hls.interstitial",START-DATE="2025-06-30T20:14:26.497Z",DURATION=10.000,X-ASSET-URI="https://wv-cdn-00-00.flowplayer.com/7bb18344-08f9-4c1e-84a7-80c1007aa99b/cmaf/6089d839-d699-424b-b914-445152e25115/playlist.m3u8",X-RESUME-OFFSET=0,X-RESTRICT="SKIP,JUMP" |
| 134 | +#EXTINF:4.0, |
| 135 | +media_10.ts |
| 136 | +#EXTINF:4.0, |
| 137 | +media_11.ts |
| 138 | +#EXTINF:4.0, |
| 139 | +media_12.ts |
0 commit comments