Giter VIP home page Giter VIP logo

hlsparserj's Introduction

HLSParserJ

Introduction

hlsparserj is a Java library for parsing HTTP Live Streaming (HLS) playlist files. It is compliant with Version 12 of the Pantos spec:

http://tools.ietf.org/html/draft-pantos-http-live-streaming-12

Examples

Parse a Master Playlist from an HTTP Endpoint

package com.comcast.viper.hlsparserj;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;

import com.comcast.viper.hlsparserj.tags.master.StreamInf;

public class Test {

    public static void main(String[] args) throws MalformedURLException, IOException {

        IPlaylist playlist = PlaylistFactory.parsePlaylist(PlaylistVersion.TWELVE, new URL("http://localhost/index.m3u8"));

        if (playlist.isMasterPlaylist()) {

            MasterPlaylist mp = (MasterPlaylist) playlist;
            for(StreamInf stream : mp.getVariantStreams()) {
                System.out.println(MessageFormat.format(
                    "Program ID: [{0}]; Bandwidth: [{1}]; Codecs: [{2}]; Resolution: [{3}]; URI: [{4}];",
                        new Object[] {
                            stream.getProgramId(),
                            String.valueOf(stream.getBandwidth()),
                            stream.getCodecs(),
                            stream.getResolution(),
                            stream.getURI()
                        }
                ));
            }
        }
    }
}

Find the Variant Playlist from the Master Playlist with the Highest Bitrate:

    // Get the playlist, but make sure it's a master playlist returned
    Playlist genericPlaylist = PlaylistFactory.parsePlaylist(PlaylistVersion.TWELVE, is);
    if (!genericPlaylist.isMasterPlaylist()) {
	    throw new Exception("Expected a master playlist but got a media playlist");
    }
    MasterPlaylist playlist = (MasterPlaylist)genericPlaylist;

    URL topBitrateVariant = null;
    int highestBitrate = Integer.MIN_VALUE;
    for (StreamInf variant : playlist.getVariantStreams()) {
    	if (variant.getBandwidth() > highestBitrate) {
    		topBitrateVariant = new URL(variant.getURI());
    	}
    }

Developer Notes

How to Add New/Custom Tags

  1. Extend the abstract Tag class and create a new class for your tag in com.comcast.viper.hlsparserj.tags.
  • Add getter methods for the attributes of your tag. See the Media object for an example.
  • Unnamed attributes (e.g. EXT-X-VERSION:4) are referred to as UNNAMEDATTR[num]. See the Version object for an example.
  1. Add a new name for your tag to com.viper.hlsparserj.tags.TagNames
  • Also add the static block to register this new tag with the TagFactory
  1. Create a new playlist version in com.viper.hlsparserj.PlaylistVersion
  • Numeric version identifiers should be reserved for Pantos spec-compliant implementation
  • Create a new package, similar to the v12 package
  • Extend either MasterPlaylist or MediaPlaylist, depending on where your tag lives
  • Add a getter method to this extension. See the top level MasterPlaylist class for examples

License

Copyright 2014 Comcast Cable Communications Management, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

hlsparserj's People

Contributors

vipercoder avatar masterjk avatar lucasweb78 avatar

Watchers

TG 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.