setup-adaptive-streaming-RTMP-800

DASH and HLS Live Streaming

Bitmovin DASH and HLS live streaming seamlessly integrates with our VoD encoding concepts such as outputs and encoding profiles. This means that you can create live streams with arbitrary resolutions and bitrates for MPEG-DASH and HLS. You could then connect this livestream with an output, i.e. Google Cloud Storage (GCS) or Amazon S3 and all segments as well as the manifests will be written to that storage. You could use this output storage as origin for your CDN or for multiple CDNs. This works well with GCS as Google offers a CDN Interconnect for several CDNs such as Fastly, Level3, HighWinds and CloudFlare. But also AWS S3 could be easily connected with their Cloudfront CDN and provides you an out-of-the-box solution in one cloud.

DASH and HLS Live streaming in the Bitmovin portal

Our live streaming feature is available through our API but also through the web interface. Just select “Create new Live Stream” under Live to create a live stream for MPEG-DASH and HLS. You need to configure the live stream name, stream key, timeshift, encoding profile and output.

create-live-stream

The configuration variables have the following meaning:

  • Livestream-Name: Arbitrary name to identify your livestream
  • Stream-Key: The stream key identifies your stream in the bitmovin encoding service
  • Timeshift: Timeshift buffer in seconds that enables live DVR for your clients
  • Encoding Profile: The encoding configuration for MPEG-DASH and HLS that contains the resolutions and bitrates of your encoded stream
  • Output: An output location such as Google Cloud Storage to which all segments and the manifests are transfered

API based MPEG-DASH and HLS live streaming

Our live streaming could be fully controlled through our REST-API or through one of our API clients, for example Python. In the following we will describe a simple example with Python to setup your live stream using the Python API client:

  1. Follow the instructions on github to setup bitcodin-python.
  2. Make sure to set the correct API key:
    bitcodin.api_key = 'INSERT YOUR API KEY'
  3. Create an Google Cloud Storage Output where the MPEG-DASH and HLS files will be transferred to
            date = datetime.datetime.today()
            prefix = "%s%d%d%d%d%d%d" % ('livestream', date.year, date.month, date.day, date.hour, date.minute, date.second)
    
            output = bitcodin.GCSOutput(
            name='Livesteam Output',
            access_key='Your GCS access key',
            secret_key='Your GCS secret key',
            bucket='Your bucket name',
            prefix=prefix,
            make_public=True
            )
    
            output = bitcodin.create_output(output)
            
  4. Create an Encoding Profile for MPEG-DASH and HLS Output
    video_configs = list()
    
    # 3 MBIT, 1920x1080, FULL HD
    video_configs.append(bitcodin.VideoStreamConfig(
        default_stream_id=0,
        bitrate=3000000,
        profile='Main',
        preset='standard',
        height=1080,
        width=1920
    ))
    # 1,5 MBIT, 1280x720, 720p
    video_configs.append(bitcodin.VideoStreamConfig(
        default_stream_id=0,
        bitrate=1500000,
        profile='Main',
        preset='standard',
        height=720,
        width=1280
    ))
    # 1 MBIT, 640x480, 480p
    video_configs.append(bitcodin.VideoStreamConfig(
        default_stream_id=0,
        bitrate=1000000,
        profile='Main',
        preset='standard',
        height=480,
        width=640
    ))
    
    # CONFIGURE AUDIO REPRESENTATION
    audio_configs = list()
    
    # 256 kbps
    audio_configs.append(bitcodin.AudioStreamConfig(
        default_stream_id=0,
        bitrate=256000
    ))
    
    live_profile = bitcodin.EncodingProfile('Live Stream profile', video_configs, audio_configs)
    live_profile = bitcodin.create_encoding_profile(live_profile)
            
  5. Set your stream key and the timeshift buffer and start your live stream
    stream_key = "stream"
    time_shift = 120
    live_stream = bitcodin.LiveStream("test live stream",
                                      stream_key,
                                      live_profile.encoding_profile_id,
                                      time_shift,
                                      output.output_id)
    
    live_stream = bitcodin.create_live_instance(live_stream)
    
    print(vars(live_stream))
            
  6. Get the RTMP input url and the MPD/M3U8 manifest urls for playback
    while live_stream.status != 'RUNNING':
        live_stream = bitcodin.get_live_instance(live_stream.id)
        print(vars(live_stream))
        if live_stream.status == 'ERROR':
            print("Error occurred during live stream creation!")
            sys.exit(-1)
        time.sleep(2)
    
    print("Ready to stream. RTMP URL: %s" % live_stream.rtmp_push_url)
    print("MPD URL: %s\nHLS URL: %s\nSTREAM KEY: %s\n" % (live_stream.mpd_url, live_stream.hls_url, live_stream.stream_key))
            

RTMP Input Examples

To input a video stream into our live stream encoders you can use any client (ffmpeg, Open Broadcaster, etc.) or encoder (Elemental, Envivio, Cisco, etc.) that supports RTMP push!

ffmpeg

Here is an example ffmpeg command that can be used to input a video stream into our live stream encoders:

ffmpeg -re -i <input_file> -c copy -f flv <rtmp_push_url retrieved from api>/<your_stream_key>

Open Broadcaster

Open Broadcaster could also be used to ingest videos into the bitmovin live streaming encoders. The important settings are under Broadcast settings. Basically you will have to select the Live Stream mode and Streaming Service is custom so that you are able to input the RTMP push url that you get from the bitmovin live streaming encoders. The stream key must be set to the value that has been provided during the live streaming setup with bitmovin.

stream_setup_small

Under encoding it is most important to set the correct audio sample rate (Format) according to the sample rate that has been set in the encoding profile. If the sample rate of the input stream and the encoding profile differ this could lead to synchronization issues of audio and video. If no sample rate is set in the encoding profile, bitmovin chooses the sample rate automatically based on the input stream.

encoding_settings_small

Another important setting is under Video. Same as for audio it is important to set the same frame rate (FPS) rate for video as set in the bitmovin encoding profile because otherwise synchronization issues of audio and video could occur. If no frame rate is set in the encoding profile, bitmovin chooses the frame rate automatically based on the input stream.

video_settings_small

Playback your MPEG-DASH and HLS live stream

Playback your video stream with an MPEG-DASH and/or HLS compatible player such as the bitmovin player, dash.js, JWPlayer or Flowplayer. The first step is that you enable CORS on your origin, which allows streaming through HTML5 and also add a crossdomain.xml to enable Flash based streaming. If you want to know more why this is important you can take a look at our CORS and Crossdomain.xml – What you need to know blog post.

Enable CORS and crossdomain.xml on GCS

To enable MPEG-DASH streaming through HTML5 you need to enable “Cross-Origin Resource Sharing” (CORS). Just follow the google documentation. An example CORS configuration could look like the following:

[
  {
    "origin": ["*"],
    "responseHeader": ["application/json"],
    "method": ["GET","HEAD"],
    "maxAgeSeconds": 3600
  }
]

To enable MPEG-DASH & HLS playback in Flash, add a crossdomain.xml in the root directory of your GCS Bucket.

Testing

If you want to simply test your video stream if everything is working as expected you can use the following URL for MPEG-DASH or HLS and test it on our website directly:

Setup live stream playback with the bitmovin player

To playback your content you can easily embed our player. All needed information, as well as the player itself, can be found in the player overview tab.

setup-player

Beneath your personal player key, all relevant information and documentation will be provided on this overview page. Furthermore, you can specify the domains you want to use with the player, via the “Add New Domain(s)” functionality, seen in the screenshot below.

Prepare a Sample Page

Next step is to download a preconfigured sample page, which demonstrates the player setup. This can be done, by using the download code button in the embed tab, like shown in the below image.

sample-page

To configure the player you simply have to change the player config object (lines 102-104 within the sample page). Just replace the values for dash, hls, progressive and poster (not needed entries can be deleted) pointing to the location of the MPD and M3U8 of your output.


source: {
  dash: '//path/to/your/dash-manifest.mpd',
  hls: '//path/to/your/hls-playlist.m3u8'
}

Publish

Last step is to upload your sample page to your webserver. Once you open the page, you will see your video playing with low startup-delay, no buffering and in the best possible quality!

Back to Top
Simple Share Buttons