NAP
Public Member Functions | Public Attributes | List of all members
Video Class Referencefinal

#include <video.h>

Public Member Functions

 Video (const std::string &path)
 
virtual ~Video ()
 
 Video (Video &)=delete
 
Videooperator= (const Video &)=delete
 
 Video (Video &&)=delete
 
Videooperator= (Video &&)=delete
 
virtual bool init (utility::ErrorState &errorState)
 
Frame update (double deltaTime)
 
void play (double time=0.0)
 
bool isPlaying () const
 
void stop (bool blocking)
 
void seek (double seconds)
 
double getCurrentTime () const
 
double getDuration () const
 
int getWidth () const
 
int getHeight () const
 
const std::string & getPath () const
 
bool hasAudio () const
 
bool audioEnabled () const
 

Public Attributes

bool mLoop = false
 If the video needs to loop. More...
 
float mSpeed = 1.0f
 Video playback speed. More...
 
nap::Signal< Video & > mDestructedSignal
 This signal will be emitted before the Video resource is destructed. More...
 

Description

Decodes a video using FFMPEG in the background. It is NOT recommended to manually (at run-time) create a nap::Video. Use the nap::VideoPlayer instead. The nap::VideoPlayer consumes frames, produced by a video, when they are ready to be presented. This object does not contain any textures, only FFMPEG related content.

Call init() after construction and start() / stop() afterwards. On initialization the video file is opened, streams are extracted and the video / audio state is initialized. A video stream is required, the audio stream is optional. Use a nap::VideoAudioComponent to decode and output the audio stream. On start() the IO and decode threads are spawned. On stop() the IO and decode threads are stopped. The av and codec contexts are freed on destruction. Keeping the format and codec contexts in memory ensures the loaded video can be started and stopped fast.

Collaboration diagram for Video:
[legend]

Constructor & Destructor Documentation

◆ Video() [1/3]

Video ( const std::string &  path)
Parameters
paththe video file on disk

◆ ~Video()

virtual ~Video ( )
virtual

◆ Video() [2/3]

Video ( Video )
delete

Copy is not allowed

◆ Video() [3/3]

Video ( Video &&  )
delete

Move is not allowed

Member Function Documentation

◆ audioEnabled()

bool audioEnabled ( ) const

Returns if audio decoding and playback is enabled. This is the case when there is an audio stream available and audio decoding is explicitly enabled.

Returns
whether audio decoding and playback is enabled.

◆ getCurrentTime()

double getCurrentTime ( ) const
Returns
The current playback position, in seconds.

◆ getDuration()

double getDuration ( ) const
Returns
The duration of the video in seconds.

◆ getHeight()

int getHeight ( ) const
Returns
Height of the video, in pixels.

◆ getPath()

const std::string& getPath ( ) const
Returns
path to the video file on disk

◆ getWidth()

int getWidth ( ) const
Returns
Width of the video, in pixels.

◆ hasAudio()

bool hasAudio ( ) const
Returns
Whether this video has an audio stream.

◆ init()

virtual bool init ( utility::ErrorState errorState)
virtual

Initializes the video. Finds decoder, sets up everything necessary to start playback.

Parameters
errorStateContains detailed information about errors if this function return false.
Returns
True on success, false otherwise.

◆ isPlaying()

bool isPlaying ( ) const

Check whether the video is currently playing

Returns
True if the video is currently playing, false if not

◆ operator=() [1/2]

Video& operator= ( const Video )
delete

Copy assignment is not allowed

◆ operator=() [2/2]

Video& operator= ( Video &&  )
delete

Move assignment is not allowed

◆ play()

void play ( double  time = 0.0)

Starts playback of the video at the given time in seconds. This will spawn the video IO and decode threads in the background. Video is stopped before being started.

Parameters
timethe offset in seconds to start the video at.

◆ seek()

void seek ( double  seconds)

Seeks within the video to the time provided. This can be called during playback.

Parameters
secondsvideo offset in seconds.

◆ stop()

void stop ( bool  blocking)

Stops playback of the video. The video IO and decode threads are stopped.

Parameters
blockingif the calling thread waits for the IO and decode thread to stop.

◆ update()

Frame update ( double  deltaTime)

Returns a newly decoded frame if available, an invalid frame otherwise. Always call .free() after processing frame content! This is a non-blocking call.

Parameters
deltaTimetime in seconds in between calls.
Returns
a newly decoded frame if available, an invalid frame otherwise.

Member Data Documentation

◆ mDestructedSignal

nap::Signal<Video&> mDestructedSignal

This signal will be emitted before the Video resource is destructed.

◆ mLoop

bool mLoop = false

If the video needs to loop.

◆ mSpeed

float mSpeed = 1.0f

Video playback speed.