Skip to main content

A FFmpeg module which could provide a class for encoding, decoding, or streaming a video in any format.

Project description

FFmpeg-Encoder-Decoder-for-Python

This is a mpegCoder adapted from FFmpeg & Python-c-api. Using it you could get access to processing video easily. Just use it as a common module in python like this.

import mpegCoder
Branch Description
master The source project of mpegCoder, Windows version.
master-linux The source project of mpegCoder, Linux version.
example-client-check A testing project of the online video stream demuxing.
example-client-player A testing project of the simple online video stream player.

Documentation

The documentation could be reviewed here:

https://cainmagi.github.io/FFmpeg-Encoder-Decoder-for-Python

Brief introduction of this project

This project is also named as "FFmpeg-Encoder-Decoder-for-Python". It is implemented based on FFMpeg, Python-C-API and C++11. It is under GPL v3 License, and recommended for researching purposes. The project could be used for processing or streaming videos.

With this package, users could:

  • Make use of all FFMpeg video encoders and decoders. When decoding a video (or an online stream), like the original FFMpeg (C version), the provided APIs could detect the video format and codec format automatically. When encoding a video, users could control the codec format, bit rate and some other options by setting parameters.
  • Work with FFMpeg directly. This project invokes the FFMpeg C APIs in the bottom level. Unlike ffmpeg-python and pyffmpeg, our project is not driven by the FFMpeg CLI interfaces. The data format used by this package is np.ndarray. In other words, our project enables users to combine numpy and FFMpeg directly.
  • Frame-level APIs. Unlike pyffmpeg, this package is not a simple wrapper of FFMpeg. Users could works on the frame-level APIs. For example, when decoding a video, users could get the data frame-by-frame. Each frame is a 3D np.ndarray.
  • Pre-compiled package. This package has been pre-compiled by the author. If users download the dependent dynamic libraries (.so or .dll), they do not need to compile the package by themself.

However, users could not work with this project in such cases:

  • Platform limited. Currently, we only support Linux and Windows. The Linux release is pre-compiled on Debian. It has been only tested in Ubuntu, Debian and Windows. In other cases, the pre-compiled library may not work. Users may need to compile the package by themselves.
  • Version limited. Currently, our project works with FFMpeg 4.4, and 5.0. Users need to download the dependent dynamic libraries to make the package work. The pip version is able to download the libraries automatically. The legacy versions of this project supports FFMpeg 3.3, 3.4.2 and 4.0. However, the legacy built packages are not technically supported now.
  • Audio not supported. Although the original FFMpeg supports both video and audio streams, our project only works on video streams. For example, if a video contains audio streams, our package would omit all audio frames in the bottom level. In other words, you could not perform audio analysis now. In the future (v4), we may support the audio frame analysis.
  • Filters not supported. Although the original FFMpeg supports some video processing tools (avfilter and postproc), our implementation drops these modules. Instead, we suggest that users should process the frames with pillow or openCV. On the other hand, our implementation still supports frame scaling and re-sampling (supported by swscale and swresample).

An example of the usage

Here we show an example of transcoding a video with our decoder and encoder. To learn more details, please review the documentation.

import mpegCoder

d = mpegCoder.MpegDecoder()
d.setParameter(nthread=4)
opened = d.FFmpegSetup('test-video.mp4')  # Setup the decoder
e = mpegCoder.MpegEncoder()
e.setParameter(decoder=d, codecName='libx265', videoPath='test-video-x265.mp4', nthread=8)  # inherit most of parameters from the decoder.
opened = opened and e.FFmpegSetup()  # Setup the encoder.
if opened:  # If either the decoder or the encoder is not loaded successfully, do not continue.
    p = True
    while p is not None:
        p = d.ExtractGOP()  # Extract current GOP.
        if p is not None:
            for i in p:  # Iterate every frame.
                e.EncodeFrame(i)  # Encode current frame.
    e.FFmpegClose() # End encoding, and flush all frames in cache.
e.clear()  # Clean configs of the encoder.
d.clear()  # Close configs of the decoder.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

mpegCoder-3.2.4-cp310-cp310-win_amd64.whl (20.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

mpegCoder-3.2.4-cp310-cp310-manylinux1_x86_64.whl (21.3 kB view hashes)

Uploaded CPython 3.10

mpegCoder-3.2.4-cp39-cp39-win_amd64.whl (20.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

mpegCoder-3.2.4-cp39-cp39-manylinux1_x86_64.whl (21.3 kB view hashes)

Uploaded CPython 3.9

mpegCoder-3.2.4-cp38-cp38-win_amd64.whl (20.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

mpegCoder-3.2.4-cp38-cp38-manylinux1_x86_64.whl (21.3 kB view hashes)

Uploaded CPython 3.8

mpegCoder-3.2.4-cp37-cp37m-win_amd64.whl (20.7 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

mpegCoder-3.2.4-cp37-cp37m-manylinux1_x86_64.whl (21.2 kB view hashes)

Uploaded CPython 3.7m

mpegCoder-3.2.4-cp36-cp36m-win_amd64.whl (20.8 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

mpegCoder-3.2.4-cp36-cp36m-manylinux1_x86_64.whl (21.3 kB view hashes)

Uploaded CPython 3.6m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page