ofVideoPlayer

The ofVideoPlayer class loads in a movie file via quicktime in windows and OSX or gstreamer in linux, and offers various controls to play the movie, control the properties of the movie, and to access the pixels of a given frame.

Example:

ofVideoPlayer myPlayer;

ofVideoPlayer methods

loadMovie(...)

bool ofVideoPlayer::loadMovie(string name)

Load a movie file (fileName) into that object. It will look for the movie file inside of the data/ folder. The movie does not automatically play once loaded.

Example:

ofVideoPlayer myPlayer;
myPlayer.loadMovie("myMovie.mov");

closeMovie()

void ofVideoPlayer::closeMovie()

Closes the movie file and de-allocates resources.

Example:

ofVideoPlayer myPlayer;
myPlayer.loadMovie("myMovie.mov"); //Loads video resources
myPlayer.closeMovie(); //Unloads video resources

close()

void ofVideoPlayer::close()

Calls the closeMovie() function, which closes the movie file and de-allocates resources.

update()

void ofVideoPlayer::update()

Calls the idleMovie() function. This function idles the movie player, so that the movie can play. If you don't call it, when the movie is playing then you may encounter problems, especially on windows machines.

idleMovie()

void ofVideoPlayer::idleMovie()

This function idles the movie player, so that the movie can play. If you don't call it, when the movie is playing then you may encouter problems, especially on winodws machines.

play()

void ofVideoPlayer::play()

Plays the movie. If the movie has been stopped or paused it will the continue playback at the point it was stopped.

stop()

void ofVideoPlayer::stop()

Stops the movie.

isFrameNew()

bool ofVideoPlayer::isFrameNew()

For example, if the pixels are new, you could then process them.


if (myMovie.isFrameNew()){
    // do something
}

getPixels()

unsigned char * ofVideoPlayer::getPixels()

For example, to get the red, green, and blue of the pixel at (100,20):

unsigned char * pixels = myMovie.getPixels();
int widthOfLine = myMovie.width;  // how long is a line of pixels
int red     = pixels[(20 * widthOfLine) + 100 * 3    ];
int green   = pixels[(20 * widthOfLine) + 100 * 3 + 1];
int blue    = pixels[(20 * widthOfLine) + 100 * 3 + 2];

getPosition()

float ofVideoPlayer::getPosition()

Returns the position of the playhead in seconds.

getSpeed()

float ofVideoPlayer::getSpeed()

Returns the speed that the movie is being played at as a floating point number. 1 = normal speed, 0 = paused, -1 = backwards.

getDuration()

float ofVideoPlayer::getDuration()

Returns the duration of the movie in seconds as a floating number.

getIsMovieDone()

bool ofVideoPlayer::getIsMovieDone()

Returns whether the movie has played all the way until the end.

setPosition(...)

void ofVideoPlayer::setPosition(float pct)

Sets the position of the playhead to a given percentage through the movie. This can be used to scrub through a movie.

setVolume(...)

void ofVideoPlayer::setVolume(int volume)

Sets the volume of a movie as it plays. The maximum values is 100, 0 is silent.

setLoopState(...)

void ofVideoPlayer::setLoopState(int state)

Sets the looping state of the movie. Deafult behavior is to loop. There are three options:


OF_LOOP_NONE - don't loop, the movie will stop when it gets to the last frame (or first frame, if playing backwards)
OF_LOOP_NORMAL - loop normally (the last frame loops to the first frame)
OF_LOOP_PALINDROME - loop back and forth

setSpeed(...)

void ofVideoPlayer::setSpeed(float speed)

Sets the speed of the movie that is playing. 1 = normal, 2 = 2x as fast, 0 = stopped, -1 = backwards, etc;

setFrame(...)

void ofVideoPlayer::setFrame(int frame)

Sets the current frame of the video. Should be used only if you know the bounds of the movie ( using totalNumberFrames() ) or store a location using getCurrentFrame();

setUseTexture(...)

void ofVideoPlayer::setUseTexture(bool bUse)

Set the usage of texture inside this object. Typically, you will want to draw the movie on screen, and so it will be necessary to use a texture, but there may be cases where it helps to not use a texture in order to save memory or for better performance. To disable the internal use of the texture, you can load the movie like this:


myMovie.setUseTexture(false);
myMovie.loadMovie("blah.mov");

getTextureReference()

ofTexture ofVideoPlayer::getTextureReference()

Returns a reference to the videoPlayer's texture.

draw(...)

void ofVideoPlayer::draw(float x, float y, float w, float h)

Draws the texture of the movie player class at the position (x,y) with the given width (w) and height (h).

draw(...)

void ofVideoPlayer::draw(float x, float y)

Draws the texture of the movie player class as the position (x,y) with the internal width and height of the loaded movie.

setPaused(...)

void ofVideoPlayer::setPaused(bool bPause)

Sets the paused state of the movie. Use "true" to pause and false to unpause.

getCurrentFrame()

int ofVideoPlayer::getCurrentFrame()

getTotalNumFrames()

int ofVideoPlayer::getTotalNumFrames()

Get the number of frames that the movie file being played contains.

firstFrame()

void ofVideoPlayer::firstFrame()

Moves the playhead to the first frame of the movie. This can also be accomplished using setCurrentFrame(0).

nextFrame()

void ofVideoPlayer::nextFrame()

Advances the playhead by one frame.

previousFrame()

void ofVideoPlayer::previousFrame()

Reverses the playhead by one frame.

getHeight()

float ofVideoPlayer::getHeight()

Get the height of the movie file.

getWidth()

float ofVideoPlayer::getWidth()

Get the width of the movie file.

setPlayer(...)

void ofVideoPlayer::setPlayer(ofPtr< ofBaseVideoPlayer > newPlayer)

getPlayer()

ofPtr ofVideoPlayer::getPlayer()

setPixelFormat(...)

void ofVideoPlayer::setPixelFormat(ofPixelFormat pixelFormat)

getPixelsRef()

ofPixelsRef ofVideoPlayer::getPixelsRef()

setLoopState(...)

void ofVideoPlayer::setLoopState(ofLoopType state)

getLoopState()

int ofVideoPlayer::getLoopState()

draw(...)

void ofVideoPlayer::draw(const ofPoint &p)

draw(...)

void ofVideoPlayer::draw(const ofRectangle &r)

setAnchorPoint(...)

void ofVideoPlayer::setAnchorPoint(float x, float y)

isPaused()

bool ofVideoPlayer::isPaused()

isLoaded()

bool ofVideoPlayer::isLoaded()

isPlaying()

bool ofVideoPlayer::isPlaying()

ofVideoPlayer variables

int width

int ofVideoPlayer::width

Variable containing the width of the video.

int height

int ofVideoPlayer::height

Variable containing the height of the video.

float speed

float ofVideoPlayer::speed

Contains the playback speed of the video. 1.0 is the normal speed. 2.0 is double the normal speed, -1 is backwards etc.

bool bLoaded

bool ofVideoPlayer::bLoaded

A boolean that describes if the movie loaded properly.

int nFrames

int ofVideoPlayer::nFrames

Variable containing the number of frames of the video.

unsigned char * pixels

unsigned char * ofVideoPlayer::pixels

Array of pixels that represents the current frame of live video. The data is stored as RGB in an array which is the size: width*height*3.

bool bHavePixelsChanged

bool ofVideoPlayer::bHavePixelsChanged

A boolean controlling if pixels have change.

ofTexture tex

ofTexture ofVideoPlayer::tex

ofTexture used by the video player class.

bool bUseTexture

bool ofVideoPlayer::bUseTexture

bUseTexture enables and disables the use of ofTexture in our video player.

bool allocated

bool ofVideoPlayer::allocated

Boolean varible containing true if the texture has been already allocated inside our video player.