Home

Awesome

ffio

<p align="left"> <img src="https://img.shields.io/badge/version-2.0.4-green" /> <img src="https://img.shields.io/docker/pulls/jionlp/pyffmpeg?color=brightgreen" /> </p> <img src="https://github.com/dongrixinyu/ffio/blob/main/image/ffio_logo.jpg?raw=true" style="width:100px;height:70px" />

ffio is not just another Python wrapper of the FFmpeg executable. It directly integrates the FFmpeg C API, and is mainly designed for streaming that specifically deals with raw RGB data.

Insight

[Video]        [FFIO]      [Raw-RGB-Image]     [FFIO]          [Video]
   ● ------> (decoding)  ------>  □
                                  ◘
                                  □  ----->  (encoding) ------->  ●

There are primarily two ways to utilize ffio:

  1. Decoding: extract images in RGB format from a provided video, either from a local file or a live stream.
  2. Encoding: encode provided RGB images, write them into a local video file or a live stream.

Naturally, you can chain two ffio.FFio instances together to facilitate video transformation. However, if you don't have to do some stuff with raw RGB images, simply consider using ffmpeg as a more straightforward solution.

Just keep in mind, the main character in ffio are images in raw format.

Features

Installation

ffio depends on FFmpeg dynamic linking libraries. So it's necessary to install FFmpeg before ffio.

We provide 3 methods to install ffio.

If you are not familiar with C, and not willing to deal with anything about C:

1. Pull docker image from docker hub (recommended)

$ docker pull jionlp/ffio:latest
$ docker run -it jionlp/ffio:latest /bin/bash  # run into the container.
$ (in docker container) python

Quick start

import ffio
decoder = ffio.FFIO("/path/to/target")
image   = decoder.decode_one_frame()

Or, if you wanna build a docker by yourself from a custom GitHub branch:

2. Build docker image by yourself from GitHub

You can first clone this repo via git, and then build a docker with all libs installed. You do not need to configure compilation params anymore.

$ git clone https://github.com/dongrixinyu/ffio
$ cd ffio
$ docker build -t jionlp/ffio:(your custom version) .

If you wanna run ffio in your host OS, rather than a docker container, you can:

3. Install ffio by yourself

This method is a little bit difficult if you are not familiar with gcc, make, cmake and trivial concerning ffmpeg compilation. But if you can configure ffmpeg, python include path, dynamic library path smoothly, just take a try.

Pre-Installation-requirements

Installation method

$ git clone https://github.com/dongrixinyu/ffio
$ cd ffio
$ ./compiler.sh [debug|release] # you should configure all kinds of paths according to your OS environment, otherwise you would encounter errors.
$ pip install -e .

Usage

Here is Documentation. Examples of how to use ffio are given in the hyperlinks:

functiondescription
decode video framesTo grab frames from an online stream or a video file <br/>suffixed by mp4 or flv, etc.
decode video frames to shmDecoded rgb bytes will be written to SharedMemory.
encode video framesTo insert frames in Numpy format into a video stream
encode video frames from shmEncode rgb bytes from SharedMemory.
ffio.cuda_is_available()returns a bool value, indicating that if cuda is available, and print info of GPU.
ffio.available_gpu_memory()returns a list, indicating how much GPU memory is available to use for every GPU card, excluding that been occupied. It is measured in M(mega) unit. It is helpful for deciding whether to set hw_enabled and pix_fmt_hw_enabled to True.

Reference