PL_MPEG

用于解码 MPEG1 视频和 MP2 音频的单文件 C 库。「Single file C library for decoding MPEG1 Video and MP2 Audio」

Github stars Tracking Chart

PL_MPEG -- MPEG1 视频解码器, MP2 音频解码器, MPEG-PS 解复用器。

MIT 授权的 C/C++ 单文件库。

参见 pl_mpeg.h 获取文档。

为什么要这样做?

这是一种将视频回放添加到应用或游戏中的简单方法。其他解决方案,比如 ffmpeg 需要巨大的库和大量的胶水代码。

MPEG1 是一种旧的、效率低的编解码器,但是对于许多用例来说,它仍然足够好。所有与 MPEG1 和 MP2 相关的专利都已经过期,所以现在它是完全免费的。

这个库没有使用任何SIMD指令,但由于相对简单的编解码器,它仍然设法解码4k60fps的视频在一个CPU核心(在我的i7-6700k至少)。

这个库不使用任何 SIMD 指令,但由于编解码器的相对简单,它仍然设法在单个 CPU 核心上解码 4k60fps 的视频(至少在我的 i7-6700k 上)。

使用示例

PL_MPEG 的编码

大多数包含 MPEG1 视频(MPEG1)和 MPEG1 音频层 II(mp2)流的 MPEG-PS(.mpg)文件,应该可以使用 PL MPEG。注意,.mpg 文件也可以包含 MPEG2 视频,这个库不支持 MPEG2 视频。

你可以使用 ffmpeg 将视频编码成合适的格式。

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

如果你只是想快速测试这个库,可以试试这个文件。

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

局限性

  • 没有错误报告。PL_MPEG 会默默地忽略任何无效的数据。
  • 忽略 MPEG-PS 容器中数据包的 pts(演示时间戳)。这可能会导致一些文件的同步问题。
  • 可能是 bug。


(First version translated and edited by vz on 2020.12.19)

Main metrics

Overview
Name With Ownerjmz331/gpinyin
Primary LanguageGo
Program languageC (Language Count: 1)
PlatformiOS, Mac
License:
所有者活动
Created At2015-02-25 07:42:11
Pushed At2015-04-08 15:20:22
Last Commit At2015-04-09 00:19:59
Release Count0
用户参与
Stargazers Count14
Watchers Count4
Fork Count7
Commits Count12
Has Issues Enabled
Issues Count1
Issue Open Count0
Pull Requests Count0
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

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

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 -c:a mp2 -format mpeg output.mpg

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.
  • no seeking.
  • bugs, probably.