Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::ffmpeg::Video Class Reference

Random access to the frames of a video file, decoded into Layers. More...

#include <inviwo/ffmpeg/video.h>

+ Inheritance diagram for inviwo::ffmpeg::Video:

Classes

struct  Info
 

Public Types

using Seconds = std::chrono::duration<double>
 

Public Member Functions

std::ptrdiff_t currentFrame () const
 Index of the most recently decoded frame, or -1 if nothing has been decoded yet.
 
Seconds currentTime () const
 Presentation time of the most recently decoded frame.
 
const std::filesystem::path & filename () const
 
std::ptrdiff_t frameAt (Seconds time) const
 Index of the frame shown at time.
 
const Infoinfo () const
 
Videooperator= (const Video &)=delete
 
Videooperator= (Video &&)=delete
 
std::shared_ptr< LayerreadFrame (std::ptrdiff_t index, std::shared_ptr< Layer > reuse={})
 Decode the frame at index.
 
std::shared_ptr< LayerreadNextFrame (std::shared_ptr< Layer > reuse={})
 Decode the frame following the most recently read one.
 
void seekToFrame (std::ptrdiff_t index)
 Position the stream so that the next call to readNextFrame() returns frame index.
 
void seekToTime (Seconds time)
 Position the stream so that the next call to readNextFrame() returns the frame at time.
 
int streamIndex () const
 
Seconds timeOf (std::ptrdiff_t index) const
 Presentation time of frame index.
 
 Video (const std::filesystem::path &filename, int streamIndex=-1)
 Open filename and prepare the video stream streamIndex for decoding.
 
 Video (const Video &)=delete
 
 Video (Video &&)=delete
 

Detailed Description

Random access to the frames of a video file, decoded into Layers.

Frames are converted to a Layer format matching the source as closely as possible, see Info::format. Color videos are decoded into RGBA, grayscale videos into a single channel, and sources with more than 8 bits per component are decoded into 16 bit Layers.

Seeking is done by seeking to the closest preceding keyframe and then decoding forward. Reading frames in order is therefore substantially faster than random access.

Constructor & Destructor Documentation

◆ Video()

inviwo::ffmpeg::Video::Video ( const std::filesystem::path & filename,
int streamIndex = -1 )
explicit

Open filename and prepare the video stream streamIndex for decoding.

Parameters
filenamevideo file to open
streamIndexindex of the video stream to decode, -1 selects the best one
Exceptions
Exceptionif the file cannot be opened, holds no video stream, or if there is no decoder available for it

Member Function Documentation

◆ readFrame()

std::shared_ptr< Layer > inviwo::ffmpeg::Video::readFrame ( std::ptrdiff_t index,
std::shared_ptr< Layer > reuse = {} )

Decode the frame at index.

Parameters
indexframe to read, negative values are counted from the end, that is -1 is the last frame
reuseoptional Layer to decode into. It is only used if it is non-null and matches the format, dimensions, and type of the decoded frames, otherwise it is ignored and a new Layer is allocated.
Returns
the decoded frame, or nullptr if the stream ended before reaching index
Exceptions
RangeExceptionif index is out of bounds

◆ readNextFrame()

std::shared_ptr< Layer > inviwo::ffmpeg::Video::readNextFrame ( std::shared_ptr< Layer > reuse = {})

Decode the frame following the most recently read one.

Parameters
reuseoptional Layer to decode into,
See also
readFrame
Returns
the decoded frame, or nullptr at the end of the stream

The documentation for this class was generated from the following file: