GithubHelp home page GithubHelp logo

prebrov / iframe-playlist-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pbs/iframe-playlist-generator

0.0 1.0 0.0 2.53 MB

Python module to generate I-frame playlists for HLS video

Home Page: http://open.pbs.org/blogs/open-pbs/how-pbs-is-enabling-apples-trick-play-mode/

License: Apache License 2.0

Python 100.00%

iframe-playlist-generator's Introduction

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:

  • master_uri: the uri of the master playlist, ex.: "playlist.m3u8"

  • master_content: the content of the updated master playlist, ex.:

    """
    #EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=400000,CODECS="avc1.4d001f, mp4a.40.5"\nvideo-400k.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=150000,CODECS="avc1.4d001f, mp4a.40.5"\nvideo-150k.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5"\n
    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...'}, ...]
    

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:

  • uri: the uri of the I-frame playlist, ex.: "video-400k-iframes.m3u8"
  • content: the content of the I-frame playlist, ex.: "#EXTM3U\n..."

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

  • Replace FFmpeg dependency with a pure python MPEG transport stream parser

License

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

iframe-playlist-generator's People

Contributors

rudemateo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.