Skip to content
An experimental pure-golang MPEG-2 decoder implementation
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
pes updating for new bitreader interface Jun 11, 2018
LICENSE documentation Jan 17, 2016


Package mpeg provides an implementation of an experimental pure golang implementation of an MPEG-2 decoder. It is intended as an educational look at some of the patterns and algorithms involved in the ubiquitous technology of video compression/decompression.

This package is experimental and is not intended for use in production environments.



This library is split into four sub-packages:

  • mpeg/ts for parsing and processing MPEG-2 Transport Streams
  • mpeg/ps for parsing and processing MPEG-2 Program Streams
  • mpeg/pes for parsing and processing MPEG-2 Packetized Elementary Streams
  • mpeg/video for decoding MPEG-2 Video


Give it a spin!

go get -d

Decode a frame of video from a MPEG-2 TS and save it as a png

package main

import "os"
import "image/png"

import ""
import ""
import ""

func main() {
  // Open the file
  tsReader, err := os.Open("source.ts")

  // Decode PID 0x21 from the TS stream
  pesReader := ts.NewPayloadUnitReader(tsReader, ts.IsPID(0x21))

  // Decode the PES stream
  esReader := pes.NewPayloadReader(pesReader)

  // Decode the ES into a stream of frames
  v := video.NewVideoSequence(esReader)

  // Align to next sequence start/entry point

  // get the next frame
  frame, _ = v.Next()
  file, _ := os.Create("output.png")
  png.Encode(file, frame)
You can’t perform that action at this time.