Wowza Community

Processing: How to Use the Wowza Streaming Cloud REST API in a Simple Live Streaming Workflow

Module 2: Processing

Before you get started, you will need to have an active Wowza Streaming Cloud account with API access enabled. If you do not have an active account, you can sign up for one here.

Once you have an active Wowza Streaming Cloud account, log in at https://cloud.wowza.com, and locate your API key through the “API Access” menu item in the top-right droplist. If no Access Keys appear, you may generate one using the “Add Access Key” button in the top left of this screen (or refer to this document for more instruction).

Creating a Stream

We need to create a live stream to push content from the mobile app for distribution to viewers. Wowza Streaming Cloud supports the creation of both standard and ultra low latency streams, both of which scale automatically for delivery to global audiences of any size.

Creating a Standard HLS Live Stream

For most use cases Apple HTTP Live Streaming (HLS) live streams provide excellent compatibility and scalability.

To create a standard stream, from your application issue a post to the Wowza Streaming Cloud REST API live_stream endpoint with wowza_gocoder as the specified encoder, as shown in the sample below. This spins up a cloud live streaming instance.

Note: When adding instances, it is generally preferable to add the instance as close as possible to the source location. This sample places the instance in the Western U.S., but you should add instances that can be changed to any of the multiple available global locations.

curl -X POST --header "Content-Type: application/json" --header "wsc-api-key: [key]" --header "wsc-access-key: [key]" -d '{
   "live_stream": {
     "aspect_ratio_height": 720,
     "aspect_ratio_width": 1280,
     "billing_mode": "pay_as_you_go",
     "broadcast_location": "us_west_california",
     "closed_caption_type": "none",
     "delivery_method": "push",
     "encoder": "wowza_gocoder",
     "hosted_page": true,
     "hosted_page_sharing_icons": true,
     "name": "MyLiveStream",
     "player_countdown": false,
     "player_responsive": true,
     "player_type": "original_html5",
     "player_width": 0,
     "recording": false,
     "target_delivery_protocol": "hls-https",
     "transcoder_type": "transcoded",
     "use_stream_source": false
   }
}' "https://api.cloud.wowza.com/api/[version]/live_streams"

When successful, this call should return something like the sample below, which contains the necessary information (i.e., host port, password, primary server) to connect the mobile streaming application to the live stream.

{
   "live_stream": {
     "aspect_ratio_height": 720,
     "aspect_ratio_width": 1280,
     "billing_mode": "pay_as_you_go",
     "broadcast_location": "us_west_california",
     "closed_caption_type": "none",
     "connection_code": "033334",
     "connection_code_expires_at": "2015-11-25T12:06:38.453-08:00",
     "created_at": "2015-11-24T12:06:38.451",
     "delivery_method": "push",
     "delivery_protocols": [
       "rtmp",
       "rtsp",
       "wowz"
     ],
     "direct_playback_urls": [
       {
         "rtmp": 
         ["names, output_ids, and urls returned here"]
       }
       {
         "rtsp":
         ["names, output_ids, and urls returned here"]
       }
       {
         "wowz":
        ["names, output_ids, and urls returned here"]
       }
     ],
     "encoder": "wowza_gocoder",
     "hosted_page": true,
     "hosted_page_sharing_icons": true,
     "hosted_page_title": "MyLiveStream",
     "hosted_page_url": "in_progress",
     "id": "1234abcd",
     "low_latency": false,
     "name": "MyLiveStream",
     "player_countdown": false,
     "player_embed_code": "in_progress",
     "player_hls_playback_url": "https://[wowzasubdomain]-f.akamaihd.net/i/32a5814b_1@7217/master.m3u8",
     "player_id": "[UniqueIDReturnedHere]"
     "player_responsive": true,
     "player_type": "original_html5",
     "recording": false,
     "source_connection_information": {
       "application": "app-464b",
       "disable_authentication": false,
       "host_port": 1935,
       "password": "1234abcd",
       "primary_server": "[subdomain].entrypoint.cloud.wowza.com",
       "stream_name": "32a5814b",
       "username": "client2"
     },
     "stream_targets": [
       {
         "id": "[UniqueIDReturnedHere]"
       }
     ],
     "target_delivery_protocol": "hls-https",
     "transcoder_type": "transcoded",
     "updated_at": "2015-11-24T12:06:38.532",
     "use_stream_source": false
   }
}

Starting Your Standard HLS Stream

After you have created your standard HLS stream, you will have to start it before your GoCoder SDK application will be able to connect to it and begin publishing.

To start the stream, issue the following Put to the live_stream endpoint with the stream ID returned when you created the stream:

curl -X PUT --header "Content-Type: application/json" --header "wsc-api-key: [key]" --header "wsc-access-key: [key]" "https://api.cloud.wowza.com/api/v1/live_streams/[live_stream_id]/start"

After you have started the stream, you will be able to connect your mobile app and begin publishing a live stream. Once you have connected and begun broadcasting from your application, you can verify that your stream is making it from the mobile device to Wowza Streaming Cloud by logging into your account (https://cloud.wowza.com) and selecting the appropriate stream. You should see a preview of your stream in the preview window.

Standard live streams, by default, will automatically stop after 20 minutes without a source being detected—but it is recommended that you include functionality to stop the streams to avoid incurring unnecessary charges.

To stop the stream, issue the following Put to the live_stream endpoint with the stream ID returned when you created the stream:

curl -X PUT --header "Content-Type: application/json" --header "wsc-api-key: [key]" --header "wsc-access-key: [key]" "https://api.cloud.wowza.com/api/[version]/live_streams/[live_stream_id]/stop"

Creating an Ultra Low Latency Live Stream

Ultra low latency streaming is a great option for use cases such as interactive streaming, gaming, auctions and others where sub two-second streaming at scale (both in terms of distance and volume of viewers) is preferred or required.

Note: Access to the ultra low latency capabilities in Wowza Streaming Cloud is not automatically available for all plans.

To create an ultra low latency stream, issue the following post to the stream target endpoint:

curl -H "wsc-api-key: YOURAPIKEY" -H "wsc-access-key: YOURACCESSKEY" -H "Content-Type: application/json" -X POST -d '{
    "stream_target": {
        "type": "UltraLowLatencyStreamTarget",
        "name": "My Ultra Low Latency Stream",
        "source_delivery_method": "push",
        "enabled": true,
        "use_hls_backup": true
    }
}' "https://api.cloud.wowza.com/api/v1.1/stream_targets/"

When successful, this call should return something like the sample below, which contains the necessary information (i.e., host port, password, primary server) to connect the mobile streaming application to the live stream.

{"stream_target":{
    "id":"abcdef0g",
    "type":"UltraLowLatencyStreamTarget",
    "name":"My Stream Target",
    "provider":"wowza",
    "enabled":true,
    "stream_name":"123a4bCd5E6fghiJKLmnop7KlmNo8p90",
    "primary_url":"rtmp://origin-preview.cdn.wowza.com:1935/live/012a1bUg4T0psqaBCDEFGa2JzrKe5e23",
    "source_delivery_method":"push",
    "playback_urls":{
        "ws":["ws://edge-preview.cdn.wowza.com/live/_definst_/0P0p1aBg4C0pDE2o4FGdmc3HxI0w5d20/stream.ws",
        "wss://edge-preview.cdn.wowza.com/live/_definst_/0P0p1aBg4C0pDE2o4FGdmc3HxI0w5d20/stream.ws"],
    "wowz":[
        "wowz://edge-preview.cdn.wowza.com/live/_definst_/0P0p1aBg4C0pDE2o4FGdmc3HxI0w5d20",
        "wowzs://edge-preview.cdn.wowza.com/live/_definst_/0P0p1aBg4C0pDE2o4FGdmc3HxI0w5d20"],
    "hls":[
        "https://wowzaprod120-i.akamaihd.net/hls/live/123456/7f8a90b6/playlist.m3u8"]},
    "enable_hls":true,
    "connection_code":"1ABC23",
    "connection_code_expires_at":"YYYY-MM-DDTHH:MM:SS.SSSZ",
    "created_at":"YYYY-MM-DDTHH:MM:SS.SSSZ",
    "updated_at":"YYYY-MM-DDTHH:MM:SS.SSSZ",
    "links":[....]

Unlike standard HLS streams, ultra low latency streams do not require location identifiers or have to be started. They automatically determine the optimal ingest point, and are always on until they are deleted.