https://github.com/gen2brain/mpeg
MPEG-1 Video decoder, MP2 Audio decoder and MPEG-PS Demuxer in pure Go
https://github.com/gen2brain/mpeg
Last synced: about 1 year ago
JSON representation
MPEG-1 Video decoder, MP2 Audio decoder and MPEG-PS Demuxer in pure Go
- Host: GitHub
- URL: https://github.com/gen2brain/mpeg
- Owner: gen2brain
- License: mit
- Created: 2022-10-23T14:39:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T22:04:31.000Z (about 2 years ago)
- Last Synced: 2025-05-12T14:30:06.816Z (about 1 year ago)
- Language: Go
- Size: 21.4 MB
- Stars: 139
- Watchers: 7
- Forks: 12
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## mpeg
[](https://github.com/gen2brain/mpeg/actions)
[](https://pkg.go.dev/github.com/gen2brain/mpeg)
[](https://goreportcard.com/report/github.com/gen2brain/mpeg)
`MPEG-1` Video decoder, `MP2` Audio decoder and `MPEG-PS` Demuxer in pure Go.
### Why
This is a simple way to get video playback into your app or game.
`MPEG-1` is an old and inefficient codec, but it is still good enough for many use cases. The quality and compression ratio still holds up surprisingly well.
Decoding costs very little CPU time compared to modern video formats. All patents related to `MPEG-1` and `MP2` have expired, so it is entirely free now.
### Examples
- [frames](https://github.com/gen2brain/mpeg-examples/blob/main/frames) - extracts all frames from a video and saves them as JPEG
- [player-eb](https://github.com/gen2brain/mpeg-examples/blob/main/player-eb) - player using `Ebitengine`, also check better, [accelerated example](https://github.com/hajimehoshi/ebiten/tree/main/examples/video)
- [player-rl](https://github.com/gen2brain/mpeg-examples/blob/main/player-rl) - player using `raylib` with YUV->RGB conversion done on CPU
- [player-sdl](https://github.com/gen2brain/mpeg-examples/blob/main/player-sdl) - player using `SDL2` with accelerated YUV->RGB conversion
- [player-web](https://github.com/gen2brain/mpeg-examples/blob/main/player-web) - player using `WebGL` and `WebAudio`, see [live example](https://gen2brain.github.io/mpeg)
- [player-xv](https://github.com/gen2brain/mpeg-examples/blob/main/player-xv) - player using `X11/XVideo` and `OSS`, accelerated
### Format
Most [MPEG-PS](https://en.wikipedia.org/wiki/MPEG_program_stream) (`.mpg`) files containing [MPEG-1](https://en.wikipedia.org/wiki/MPEG-1) video (`mpeg1video`) and [MPEG-1 Audio Layer II](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II) (`mp2`) streams should work.
Note that `.mpg` files can also contain [MPEG-2](https://en.wikipedia.org/wiki/MPEG-2) video, which this library does not support.
You can encode video in a suitable format with `FFmpeg`:
```
ffmpeg -i input.mp4 -c:v mpeg1video -q:v 16 -c:a mp2 -format mpeg output.mpg
```
`-q:v` sets a fixed video quality with a variable bitrate, where `0` is the highest.
You can use `-b:v` to set a fixed bitrate instead; e.g. `-b:v 2000k` for 2000 kbit/s.
Refer to the [FFmpeg documentation](https://ffmpeg.org/ffmpeg.html#Options) for more details.
### Credits
* [pl_mpeg](https://github.com/phoboslab/pl_mpeg) by Dominic Szablewski.
* [javampeg1video](https://sourceforge.net/projects/javampeg1video/) by Korandi Zoltan.
* [kjmp2](https://keyj.emphy.de/kjmp2/) by Martin J. Fiedler.