• Stars
    star
    1,225
  • Rank 38,289 (Top 0.8 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. 🎦

M3U8

This is the most complete opensource library for parsing and generating of M3U8 playlists used in HTTP Live Streaming (Apple HLS) for internet video translations.

M3U8 is simple text format and parsing library for it must be simple too. It does not offer ways to play HLS or handle playlists over HTTP. So library features are:

  • Support HLS specs up to version 5 of the protocol.
  • Parsing and generation of master-playlists and media-playlists.
  • Autodetect input streams as master or media playlists.
  • Offer structures for keeping playlists metadata.
  • Encryption keys support for use with DRM systems like Verimatrix etc.
  • Support for non standard Google Widevine tags.

The library covered by BSD 3-clause license. See LICENSE for the full text. Versions 0.8 and below was covered by GPL v3. License was changed from the version 0.9 and upper.

See the list of the library authors at AUTHORS file.

Project status

I moved away from videostreaming years ago and directly not used this code in my projects now. Hence the project mostly abandoned. Anyway I interested in keeping the code as useful as possible. I'll keep the eye on the issues when I have the time. Time is the biggest issue :|

  1. Any patches are welcome especially bugfixes.
  2. If you want to maintain the project open the issue or directly contact me.
  3. If you have alternatives (including the forks of this project) that you prefer to maintain by self, drop a link for including to this readme.

Install

go get github.com/grafov/m3u8

or get releases from https://github.com/grafov/m3u8/releases

Documentation GoDoc

Package online documentation (examples included) available at:

Supported by the HLS protocol tags and their library support explained in M3U8 cheatsheet.

Examples

Parse playlist:

	f, err := os.Open("playlist.m3u8")
	if err != nil {
		panic(err)
	}
	p, listType, err := m3u8.DecodeFrom(bufio.NewReader(f), true)
	if err != nil {
		panic(err)
	}
	switch listType {
	case m3u8.MEDIA:
		mediapl := p.(*m3u8.MediaPlaylist)
		fmt.Printf("%+v\n", mediapl)
	case m3u8.MASTER:
		masterpl := p.(*m3u8.MasterPlaylist)
		fmt.Printf("%+v\n", masterpl)
	}

Then you get filled with parsed data structures. For master playlists you get Master struct with slice consists of pointers to Variant structures (which represent playlists to each bitrate). For media playlist parser returns MediaPlaylist structure with slice of Segments. Each segment is of MediaSegment type. See structure.go or full documentation (link below).

You may use API methods to fill structures or create them manually to generate playlists. Example of media playlist generation:

	p, e := m3u8.NewMediaPlaylist(3, 10) // with window of size 3 and capacity 10
	if e != nil {
		panic(fmt.Sprintf("Creating of media playlist failed: %s", e))
	}
	for i := 0; i < 5; i++ {
		e = p.Append(fmt.Sprintf("test%d.ts", i), 6.0, "")
		if e != nil {
			panic(fmt.Sprintf("Add segment #%d to a media playlist failed: %s", i, e))
		}
	}
	fmt.Println(p.Encode().String())

Custom Tags

M3U8 supports parsing and writing of custom tags. You must implement both the CustomTag and CustomDecoder interface for each custom tag that may be encountered in the playlist. Look at the template files in example/template/ for examples on parsing custom playlist and segment tags.

Library structure

Library has compact code and bundled in three files:

  • structure.go β€” declares all structures related to playlists and their properties
  • reader.go β€” playlist parser methods
  • writer.go β€” playlist generator methods

Each file has own test suite placed in *_test.go accordingly.

Related links

Library usage

This library was successfully used in streaming software developed for company where I worked several years ago. It was tested then in generating of VOD and Live streams and parsing of Widevine Live streams. Also the library used in opensource software so you may look at these apps for usage examples:

Project status Go Report Card

Build Status Build Status Coverage Status

DeepSource

Code coverage: https://gocover.io/github.com/grafov/m3u8

Project maintainers

Thank to all people who contrubuted to the code and maintain it. Especially thank to the maintainers who involved in the project actively in the past and helped to keep code actual:

  • Lei Gao @leikao
  • Bradley Falzon @bradleyfalzon

New maitainers are welcome.

Alternatives

On the project start in 2013 there was no any other libs in Go for m3u8. Later the alternatives came. Some of them may be more fit current standards.

Drop a link in issue if you know other projects.

FYI M3U8 parsing/generation in other languages

More Repositories

1

hulk

HULK DoS tool ported to Go with some additional features.
Go
769
star
2

plantuml2mysql

This utility parses PlantUML class diagram and generates SQL DDL for MySQL
Python
115
star
3

bcast

Broadcasting library for Go. Broadcast message of any type on a set of channels. WIP
Go
98
star
4

go-playground

GNU/Emacs mode that setup local Go playground for code snippets like play.golang.org or even better :)
Emacs Lisp
83
star
5

streamsurfer

Software for monitoring of HTTP video streams.
Go
82
star
6

rust-playground

GNU/Emacs mode that setup local playground for code snippets in Rust language.
Emacs Lisp
45
star
7

hlsprobe

Utility to probe Apple HLS streams.
Python
39
star
8

kiwi

Fast, structured, with filters and dynamic sinks. No levels. Logger & context keeper for Go language πŸ₯ It smells like a mushroom.
Go
24
star
9

shift-shift

Xorg/Wayland keyboard layout switcher.
Go
15
star
10

russian-holidays

Russian holidays for GNU/Emacs calendar πŸ“†
Emacs Lisp
14
star
11

websocket-utils

Simple utils for testing websocket connections.
Go
5
star
12

reddit-clone-example

Example of realization of Reddit-like API with Go language.
Go
5
star
13

mpegts

Mpegts stream decoder
Go
3
star
14

gorg

Org-mode parser and generator for Golang
3
star
15

quickpic-cloud-linux-downloader

Download photos from the cloud that offered by Quickpic
Go
2
star
16

broadcast

The experiment
Go
2
star
17

pin-buffer

πŸ“Pins buffer to current window in GNU/Emacs
Emacs Lisp
2
star
18

wtfm

Where's The Fucking Manual? (ok, let Write the Fabulous Manual)
Go
2
star
19

mysql-backup

Simple tool for backuping MySQL databases.
2
star
20

rule-mode

Emacs support for rule-based comments in code.
Emacs Lisp
2
star
21

slack-anything

Slack Anything offers additional ways for using Slack Chat
Go
2
star
22

keyboard

Alternative keyboard layouts. Colemacs layout for emacsers on unix.
PHP
2
star
23

go-loggers-comparison

Benchmarks of loggers for Go language.
Go
2
star
24

service

The service tree 🌳 library for Go
Go
2
star
25

aeis

Ordering chaos in ~/.emacs.d.
Emacs Lisp
2
star
26

tw

Text Widgets library.
1
star
27

viewga

Experiments with desktop UI
1
star
28

quicksand

Quicksand β€” website stress testing & DOS tool. Hulk' successor.
1
star
29

whereami

Where am I? β€” executes actions based on your geographic place
1
star
30

webhotkey

URL shortener + HTTP proxy + DNS cache: swiss knife for webdeveloper.
1
star
31

apply

Apply the command to the project directories.
1
star
32

dotemacs

My emacs config.
Emacs Lisp
1
star
33

ergodox_configurator

JavaScript
1
star
34

portage-utils

Misc utils for Gentoo portage.
Python
1
star
35

perkeep-docker

Docker build for perkeep (calimstore).
Dockerfile
1
star
36

image-resize-service

The example of image resizing HTTP-service in Go
Go
1
star
37

randfs

Go library for generating random files/filenames/directories. For testing applications that needs work with massive number of files.
Go
1
star