Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phoboslab/pl_mpeg
Single file C library for decoding MPEG1 Video and MP2 Audio
https://github.com/phoboslab/pl_mpeg
Last synced: 8 days ago
JSON representation
Single file C library for decoding MPEG1 Video and MP2 Audio
- Host: GitHub
- URL: https://github.com/phoboslab/pl_mpeg
- Owner: phoboslab
- Created: 2019-06-11T07:40:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-10T09:54:00.000Z (about 1 month ago)
- Last Synced: 2024-12-27T20:04:16.140Z (15 days ago)
- Language: C
- Size: 106 KB
- Stars: 809
- Watchers: 26
- Forks: 58
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-game-engine-dev - PL_MPEG - Single-file library for decoding MPEG1 Video and MP2 Audio. (Libraries / C)
- AwesomeCppGameDev - pl_mpeg
README
# PL_MPEG - MPEG1 Video decoder, MP2 Audio decoder, MPEG-PS demuxer
Single-file MIT licensed library for C/C++
See [pl_mpeg.h](https://github.com/phoboslab/pl_mpeg/blob/master/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).## Building
A Makefile to build the example applications is included.
- `pl_mpeg_extract_frames`: a command line tool that dumps all frames into BMPs
- `pl_mpeg_player_gl`: a video player using SDL2 and OpenGL
- `pl_mpeg_player_sdl`: a video player using SDL2 and it's built-in 2d rendererThe players require the SDL2 library to be installed.
```shell
make # build all
make extract # only build pl_mpeg_extract_frames
make player_gl # only build pl_mpeg_player_gl
make player_sdl # only build pl_mpeg_player_sdl
```## Encoding for PL_MPEG
Most [MPEG-PS](https://en.wikipedia.org/wiki/MPEG_program_stream) (`.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](http://ffmpeg.org/ffmpeg.html#Options) 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.