HLS I-frame playlist
_ generator
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:
variant master playlist sample
_I-frame playlist sample
_The function update_for_iframes
returns a standard python dictionary with these keys:
master_uri
: the uri of the master playlist, ex.: "playlist.m3u8"
master_content
: the content of the updated master playlist, ex.::
"""
video-64k.m3u8\n#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=83598,CODECS="avc1.4d001f",URI="video-400k-iframes.m3u8"\n#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=38775,CODECS="avc1.4d001f",URI="video-150k-iframes.m3u8"\n """
iframe_playlists
: a list of dictionaries, each with a uri and content for each generated I-frame playlist, ex.::
[{'uri': 'video-400k-iframes.m3u8', 'content': '#EXTM3U\n...'}, ...]
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')
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:
uri
: the uri of the I-frame playlist, ex.: "video-400k-iframes.m3u8"content
: the content of the I-frame playlist, ex.: "#EXTM3U\n..."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
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