• Stars
    star
    695
  • Rank 62,431 (Top 2 %)
  • Language
    C
  • Created almost 5 years ago
  • Updated 6 months ago

Reviews

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

Repository Details

Single file C library for decoding MPEG1 Video and MP2 Audio

PL_MPEG - MPEG1 Video decoder, MP2 Audio decoder, MPEG-PS demuxer

Single-file MIT licensed library for C/C++

See pl_mpeg.h for the documentation.

Why?

This is meant as a simple way to get video playback into your app or game. Other solutions, such as ffmpeg require huge libraries and a lot of glue code.

MPEG1 is an old and inefficient codec, but it's still good enough for many use cases. All patents related to MPEG1 and MP2 have expired, so it's completely free now.

This library does not make use of any SIMD instructions, but because of the relative simplicity of the codec it still manages to decode 4k60fps video on a single CPU core (on my i7-6700k at least).

Compilation on Linux

Use a GCC invocation like the following to build the example pl_mpeg_player program:

gcc -o pl_mpeg_player pl_mpeg_player.c $(pkg-config --cflags --libs sdl2 glew)

Example Usage

Encoding for PL_MPEG

Most MPEG-PS (.mpg) files containing MPEG1 Video ("mpeg1") and MPEG1 Audio Layer II ("mp2") streams should work with PL_MPEG. Note that .mpg files can also contain MPEG2 Video, which is not supported by this library.

You can encode video in a suitable format using ffmpeg:

ffmpeg -i input.mp4 -c:v mpeg1video -q:v 0 -c:a mp2 -format mpeg output.mpg

-q:v sets a fixed video quality with a variable bitrate, where 0 is the highest. You may use -b:v to set a fixed bitrate instead; e.g. -b:v 2000k for 2000 kbit/s. Please refer to the ffmpeg documentation for more details.

If you just want to quickly test the library, try this file:

https://phoboslab.org/files/bjork-all-is-full-of-love.mpg

Limitations

  • no error reporting. PL_MPEG will silently ignore any invalid data.
  • the pts (presentation time stamp) for packets in the MPEG-PS container is ignored. This may cause sync issues with some files.
  • bugs, probably.

More Repositories

1

qoi

The “Quite OK Image Format” for fast, lossless image compression
C
6,657
star
2

jsmpeg

MPEG1 Video Decoder in JavaScript
JavaScript
6,222
star
3

Ejecta

A Fast, Open Source JavaScript, Canvas & Audio Implementation for iOS
Objective-C
2,795
star
4

wipeout-rewrite

C
2,449
star
5

jsmpeg-vnc

A low latency, high framerate screen sharing server for Windows and client for browsers
C
2,329
star
6

Impact

HTML5 Game Engine
JavaScript
1,916
star
7

q1k3

A tiny FPS for js13k
JavaScript
1,471
star
8

underrun

Twin stick shooter game in 13kb of JavaScript/WebGL
JavaScript
1,075
star
9

JavaScriptCore-iOS

Apple's JavaScript Engine, with modified project files for iOS
C++
685
star
10

qoa

The “Quite OK Audio Format” for fast, lossy audio compression
C
641
star
11

wipeout

WipEout (PSX) Model Viewer in WebGL/Three.js
JavaScript
520
star
12

voidcall

Real time strategy game in 13kb of JavaScript/WebGL
JavaScript
365
star
13

WebGLImageFilter

Fast image filters for Browsers with WebGL support
JavaScript
322
star
14

js-hqx

hqx Pixel Art Scaling Algorithm in JavaScript
JavaScript
187
star
15

TwoPointFive

3D View Plugin for the Impact HTML5 Game Engine
JavaScript
140
star
16

Quakespasm-Rift

Quake for Oculus Rift
C
138
star
17

Asaph

A micro-blogging system, focusing on collecting links and images
PHP
97
star
18

ttt

Tiny Texture Tumbler – A JS library and an editor to create textures
HTML
78
star
19

pagenode

Pagenode – No Bullshit Content Management
PHP
68
star
20

OculusWeb

A fast and lean HTTP/WebSocket Oculus Rift Tracking Server for Windows and Mac
C
57
star
21

impact-box2d

Box2D Plugin for the Impact Game Engine
JavaScript
51
star
22

JS360

A NET framework for JavaScript on the XBox with XNA.
C#
48
star
23

json-format

JSON Pretty Printer for JavaScript
JavaScript
38
star
24

picturelicious

Social Imaging Platform
PHP
36
star
25

impact-splash-loader

A loading screen for Impact that shows the Impact logo
JavaScript
34
star
26

rectpack

Super Simple Rectangle Packing for JS
JavaScript
13
star
27

arduboy-games

My Arduboy Mini Games
C
12
star
28

jQuery-JSH

Tiny jQuery Plugin for JavaScript SyntaxHighlighting
11
star
29

pagenode-legacy

Older version of Pagenode with a complete admin interface
PHP
2
star