pbs / iframe-playlist-generator

Python module to generate I-frame playlists for HLS video
http://open.pbs.org/blogs/open-pbs/how-pbs-is-enabling-apples-trick-play-mode/
Apache License 2.0
61 stars 15 forks source link

iframe-playlist-generator

HLS I-frame playlist_ generator

Documentation

Generate I-frame playlists and an updated variant master playlist from a url::

from iframeplaylistgenerator import update_for_iframes

playlist_data = update_for_iframes('http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8')

Here are some sample files that can be generated by this script:

Data Format

The function update_for_iframes returns a standard python dictionary with these keys:

Using the Data

The returned data can be used as needed, such as uploading the playlists to an s3 bucket::

import boto

AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''

s3 = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)

bucket = s3.get_bucket('my_bucket')

master_playlist_key = bucket.new_key(playlist_data['master_uri'])
master_playlist_key.set_metadata('Content-Type', 'application/x-mpegURL')
master_playlist_key.set_contents_from_string(playlist_data['master_content'])
master_playlist_key.set_acl('public-read')

for playlist in playlist_data['iframe_playlists']:
    iframe_playlist_key = bucket.new_key(playlist['uri'])
    iframe_playlist_key.set_metadata('Content-Type', 'application/x-mpegURL')
    iframe_playlist_key.set_contents_from_string(playlist['content'])
    iframe_playlist_key.set_acl('public-read')

Alternate Usage

Alternatively, use the function create_iframe_playlist and pass it an m3u8 Playlist object to generate an I-frame playlist for that specific stream. This function returns a tuple containing an m3u8 IFramePlaylist object pointing to the new I-frame playlist, and a dictionary with these keys:

FFmpeg Installation

In order to use the current version of iframe-playlist-generator, you must have a relatively new release of FFmpeg installed. It has only been tested on 2.2.x releases. For instructions, use the FFmpeg compilation guide for your specific OS.

Alternatively, on Mac OS X the Homebrew_ package manager can be used to install FFmpeg. To install Homebrew on a Mac, run::

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

To install FFmpeg with Homebrew, run::

brew install ffmpeg

To Do

License

This module is Copyright 2014 PBS.org and is available under the Apache License, Version 2.0_.

.. _I-frame playlist: http://tools.ietf.org/html/draft-pantos-http-live-streaming-08#section-3.4.12 .. _variant master playlist sample: http://github.com/pbs/iframe-playlist-generator/tree/master/tests/samples/generated_playlists/bigbuckbunny.m3u8 .. _I-frame playlist sample: http://github.com/pbs/iframe-playlist-generator/tree/master/tests/samples/generated_playlists/bigbuckbunny-400k-iframes.m3u8 .. _m3u8: https://github.com/peter-norton/m3u8/ .. _FFmpeg: https://ffmpeg.org/index.html .. _compilation guide: https://trac.ffmpeg.org/wiki/CompilationGuide .. _Homebrew: http://brew.sh .. _Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0