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;
myPlayer.load("movies/fingers.mov");
You need to call play() for your video to begin playing:
myPlayer.play();
and update to ensure that you're grabbing new frames from the file as the video library decodes them and serves them up as textures:
void myApp::update(){
myPlayer.update(); // get all the new frames
}
Just like the ofImage, the ofVideoPlayer can be drawn:
myPlayer.draw(20,20); // draw at 20, 20 from the current transform matrix
or you can just get the pixels from the player, as we do in the videoGrabberExample in the examples:
if (vidGrabber.isFrameNew()){
int totalPixels = camWidth*camHeight*3;
unsigned char * pixels = vidGrabber.getPixels();
for (int i = 0; i < totalPixels; i++){
videoInverted[i] = 255 - pixels[i];
}
texture.loadData(videoInverted, camWidth,camHeight, GL_RGB);
}
bind( )
void bind()Binds the video texture to the current rendering context.
For advanced users who need to manually manage texture drawing without calling draw(). Only binds the texture if one exists.
See also: ofTexture::bind()
See also: http://www.opengl.org/sdk/docs/man4/html/glBindTexture.xhtml
close( )
void close()Closes the movie file releases its resources.
This is an alias for closeMovie().
See also: closeMovie()
closeMovie( )
void closeMovie()Closes the movie file and releases its resources.
This is an alias for close().
See also: close()
Example:
ofVideoPlayer myPlayer;
myPlayer.loadMovie("myMovie.mov"); //Loads video resources
myPlayer.closeMovie(); //Unloads video resources
draw( ... )
void 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.
draw( ... )
void 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).
firstFrame( )
void firstFrame()getCurrentFrame( )
int getCurrentFrame()getDuration( )
float getDuration()getHeight( )
float getHeight()getIsMovieDone( )
bool getIsMovieDone()getLoopState( )
ofLoopType getLoopState()getMoviePath( )
string getMoviePath()Get the path to the loaded video file.
If no video file is loaded this returns an empty string.
Returns: A path to the loaded video or an empty string if not loaded.
getPixelFormat( )
ofPixelFormat getPixelFormat()getPixels( )
ofPixels & getPixels()For example, to get the red, green, and blue of the pixel at (100,20):
unsigned char * pixels = myMovie.getPixels();
int nChannels = movie.getPixelsRef().getNumChannels();
int widthOfLine = myMovie.width; // how long is a line of pixels
int red = pixels[(20 * widthOfLine + 100) * nChannels ];
int green = pixels[(20 * widthOfLine + 100) * nChannels + 1];
int blue = pixels[(20 * widthOfLine + 100) * nChannels + 2];
getPixels( )
const ofPixels & getPixels()getPosition( )
float getPosition()getSpeed( )
float getSpeed()getTexture( )
ofTexture & getTexture()getTexture( )
const ofTexture & getTexture()getTexturePlanes( )
int & getTexturePlanes()getTexturePlanes( )
const int & getTexturePlanes()getTotalNumFrames( )
int getTotalNumFrames()getWidth( )
float getWidth()initDefaultPlayer( )
void initDefaultPlayer()Initialize the default player implementations.
isFrameNew( )
bool isFrameNew()This gets whether there are new pixels in your movies player. This is a way to poll the library that's actually reading your video file to see whether there's something new: For example, if the pixels are new, you could then process them.
if (myMovie.isFrameNew()){
ofPixels p = myPlayer.getPixelsRef();
// walk over each pixel and make something fun
}
isInitialized( )
bool isInitialized()isLoaded( )
bool isLoaded()Whether the resources that you've tried to load into your ofVideoPlayer have been loaded yet.
isPaused( )
bool isPaused()Whether the the ofVideoPlayer is currently paused.
isPlaying( )
bool isPlaying()Whether the the ofVideoPlayer is currently playing.
isUsingTexture( )
bool isUsingTexture()load( ... )
bool load(string name)loadAsync( ... )
void loadAsync(string name)nextFrame( )
void nextFrame()ofVideoPlayer( )
ofVideoPlayer()Constructor.
play( )
void play()previousFrame( )
void previousFrame()resetAnchor( )
void resetAnchor()Resets the ancher point of this ofVideoPlayer, if one has been set.
setAnchorPercent( ... )
void setAnchorPercent(float xPct, float yPct)Sets an anchor percentage for this ofVideoPlayer instance
setAnchorPoint( ... )
void setAnchorPoint(float x, float y)Sets anchor points for this ofVideoPlayer instance.
setFrame( ... )
void setFrame(int frame)setLoopState( ... )
void setLoopState(ofLoopType state)
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. Movie will play forward until it gets to the last frame, then plays backwards until it gets to the first frame, and so on.
setPaused( ... )
void setPaused(bool bPause)setPixelFormat( ... )
bool setPixelFormat(ofPixelFormat pixelFormat)OSX: Choose from OF_PIXELS_RGB or OF_PIXELS_RGBA
setPosition( ... )
void 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.
setSpeed( ... )
void setSpeed(float speed)setUseTexture( ... )
void 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");
setVolume( ... )
void setVolume(float volume)stop( )
void stop()unbind( )
void unbind()Unbinds the video texture from the current rendering context.
For advanced users who need to manually manage texture drawing without calling draw(). Only binds the texture if one exists.
See also: ofTexture::unbind()
update( )
void update()Update the video player's internal state to continue playback.
If normal video playback is desired, this method is usually called once per animation frame inside of ofApp::update().