phoboslab/pl_mpeg logo

phoboslab/pl_mpeg

Free

Single file C library for decoding MPEG1 Video and MP2 Audio

FreeFree tier
Type
Open Source

About phoboslab/pl_mpeg

PL_MPEG is a single-file, MIT-licensed C/C++ library for decoding MPEG1 video and MP2 audio, as well as demuxing MPEG-PS containers. It is designed to provide a simple way to get video playback into applications and games without the overhead of large libraries like FFmpeg. The library is patent-free (all MPEG1/MP2 patents have expired) and can decode 4K60fps video on a single CPU core (tested on i7-6700K) without SIMD instructions. It includes example applications: a command-line tool to extract frames as BMPs, and video players using SDL2/OpenGL or SDL2's 2D renderer. Limitations include no error reporting (silently ignores invalid data), ignoring presentation timestamps (may cause sync issues), and no support for MPEG2 video.

Key Features

Single-file C/C++ library with no external dependencies
Decodes MPEG1 Video (mpeg1) and MP2 Audio (MPEG1 Audio Layer II)
Demuxes MPEG Program Stream (MPEG-PS) containers
MIT licensed – completely free and patent-expired
Capable of decoding 4K60fps video on a single CPU core (i7-6700K tested)
Includes example applications: frame extractor, SDL2+OpenGL player, SDL2 2D player
Simple API documented in the header file pl_mpeg.h

Pros & Cons

Pros
  • Extremely simple integration – single file, no build system complexity
  • No huge library dependencies like FFmpeg or GStreamer
  • All patents related to MPEG1 and MP2 have expired, ensuring legal safety
  • Fast enough for 4K60fps decoding on a modern CPU without SIMD
  • Open source under permissive MIT license
  • Includes ready-to-use example programs for quick testing
Cons
  • No error reporting – invalid data is silently ignored, making debugging hard
  • Ignores presentation timestamps (PTS), which may cause audio/video sync issues
  • Supports only MPEG1 video and MP2 audio; no MPEG2, H.264, or other modern codecs
  • No SIMD optimizations – performance relies on CPU clock speed
  • Only handles MPEG-PS (.mpg) containers; not MP4, AVI, etc.
  • Library is minimal – lacks advanced features like seeking, streaming, or container parsing beyond demuxing

Best For

Adding video playback to games or applications with minimal codeExtracting individual frames from MPEG1 video files as BMP imagesLightweight alternative to FFmpeg for MPEG1/MP2 decodingEmbedding video in retro-style or resource-constrained software

FAQ

What formats does PL_MPEG support?
PL_MPEG decodes MPEG1 Video (mpeg1) and MPEG1 Audio Layer II (mp2) streams from MPEG-PS (.mpg) files. It does not support MPEG2 video or other container formats.
Does PL_MPEG use SIMD instructions?
No, the library does not use any SIMD instructions. It achieves 4K60fps decoding on a single CPU core (tested on an i7-6700K) thanks to the relative simplicity of the MPEG1 codec.
Is PL_MPEG free to use?
Yes, it is completely free. The library is released under the MIT license, and all patents related to MPEG1 and MP2 have expired, so there are no licensing costs or restrictions.
How do I encode video for use with PL_MPEG?
You can use FFmpeg to encode video into the required format. For example: ffmpeg -i input.mp4 -c:v mpeg1video -q:v 0 -c:a libtwolame -b:a 224k -format mpeg output.mpg. See the repository README for more details.
Does PL_MPEG provide any example programs?
Yes, the repository includes three examples: pl_mpeg_extract_frames (dumps frames as BMPs), pl_mpeg_player_gl (SDL2+OpenGL player), and pl_mpeg_player_sdl (SDL2 2D renderer player).
What are the known limitations of PL_MPEG?
The library silently ignores invalid data (no error reporting), ignores presentation timestamps (may cause sync issues), does not support MPEG2 video, and does not use SIMD optimizations.