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;
- loadMovie(...)
- closeMovie()
- close()
- update()
- idleMovie()
- play()
- stop()
- isFrameNew()
- getPixels()
- getPosition()
- getSpeed()
- getDuration()
- getIsMovieDone()
- setPosition(...)
- setVolume(...)
- setLoopState(...)
- setSpeed(...)
- setFrame(...)
- setUseTexture(...)
- getTextureReference()
- draw(...)
- setPaused(...)
- getCurrentFrame()
- getTotalNumFrames()
- firstFrame()
- nextFrame()
- previousFrame()
- getHeight()
- getWidth()
- setPlayer(...)
- getPlayer()
- setPixelFormat(...)
- getPixelsRef()
- setLoopState(...)
- getLoopState()
- draw(...)
- setAnchorPoint(...)
- isPaused()
- isLoaded()
- isPlaying()
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.
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];
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.
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).
ofVideoPlayer variables
float speed
float ofVideoPlayer::speed
unsigned char * pixels
unsigned char * ofVideoPlayer::pixels
bool bHavePixelsChanged
bool ofVideoPlayer::bHavePixelsChanged
bool bUseTexture
bool ofVideoPlayer::bUseTexture
