cosmopolitan/dsp/mpeg
Justine Tunney dc579b79cd
Productionize polished cosmoaudio library
This change introduces comsoaudio v1. We're using a new strategy when it
comes to dynamic linking of dso files and building miniaudio device code
which I think will be fast and stable in the long run. You now have your
choice of reading/writing to the internal ring buffer abstraction or you
can specify a device-driven callback function instead. It's now possible
to not open the microphone when you don't need it since touching the mic
causes security popups to happen. The DLL is now built statically, so it
only needs to depend on kernel32. Our NES terminal emulator now uses the
cosmoaudio library and is confirmed to be working on Windows, Mac, Linux
2024-09-07 06:14:09 -07:00
..
.clang-format Upgrade pl_mpeg 2024-09-06 19:10:34 -07:00
BUILD.mk Upgrade pl_mpeg 2024-09-06 19:10:34 -07:00
pl_mpeg.c Upgrade pl_mpeg 2024-09-06 19:10:34 -07:00
pl_mpeg.h Productionize polished cosmoaudio library 2024-09-07 06:14:09 -07:00
README.cosmo Upgrade pl_mpeg 2024-09-06 19:10:34 -07:00
README.md Upgrade pl_mpeg 2024-09-06 19:10:34 -07:00

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.