Skip to content
プロジェクト

概要

MPEG-1動画とMP2音声をデコードする、単一ファイルのCライブラリ

デザイン・メディア

この数値の測り方

計測したスター増加

24時間
0
7日間
+2
15日間
+5
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

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).

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 renderer

The players require the SDL2 library to be installed.

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 (.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 libtwolame -b:a 224k -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.

関連プロジェクトを探す

読み込み中…