Giter VIP home page Giter VIP logo

ffframereader's Introduction

FFFrameReader

Github All Releases GitHub release GitHub issues license donate

About

This project provides a library the wraps Ffmpeg decoding functionality into a simple to use c++ library. It is designed to allow for easily retrieving frames from a video file that can then be used as required by a host program. The library supports software decoding as well as some hardware decoders with basic conversion and processing support.

Example:

To use this library you first need to create a Stream object that is used to represent the decoded file. A default Stream object will use normal software decoding on the CPU and can be created using the following:

auto stream = Stream::getStream("filename");
if (stream == nullptr) {
    // File opening has failed
}

Streams can also be optionally passed a set of options (@see DecoderOptions) that can be used to enable hardware accelerated decoding, resizing, cropping and various other decoding parameters. For instance to use NVIDIA GPU accelerated decoding you can create decoder options as follows:

DecoderOptions options(DecodeType::Cuda);

Options for software decoding but with resizing can be created as follows:

DecoderOptions options;
options.m_scale = {1280, 720};

Once decoder options have been created they can then be used to open various files by passing them to the stream creation:

auto stream = Stream::getStream(fileName, options);

A stream object can then be used to get information about the opened file (such as resolution, duration etc.) and to read image frames from the video. To get the next frame in a video you can use the following in a loop:

auto frame = stream->getNextFrame();
if (frame == nullptr) {
    // Failed to get the next frame, there was either an internal error or the end of the file has been reached
}

This creates a frame object that has the information for the requested frame (such as its time stamp, frame number etc.). It also has the actual image data itself that can be retrieved as follows:

auto data1 = frame->getFrameData(00);

The format of the data stored in the returned pointer depends on the input video and the decoder options. By default many videos will be coded using YUV420 which in that case means there are 3 different image planes (Y,U or V planes respectively). To get a specific image plane; getFrameData can be used by passing the desired plane. This function will return a pointer to the start of the plane and the line size of each row in the image plane. The number of planes in each frame can be determined by:

auto planes = frame->getNumberPlanes();

By default when using hardware decoding the decoded frames will be output to system host memory. To keep the frames in device memory setup the decoder options such that:

options.m_outputHost = false;

In addition to just reading frames in sequence from start to finish, a stream object also supports seeking. Seeks can be performed on either duration time stamps of specific frame numbers as follows:

if (!stream->seek(2000)) {
    // Failed to seek to requested time stamp
}

ffframereader's People

Contributors

sibras avatar anibali avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.