class methods
- bind()
- close()
- closeMovie()
- draw()
- firstFrame()
- getCurrentFrame()
- getDuration()
- getHeight()
- getIsMovieDone()
- getLoopState()
- getMoviePath()
- getPixelFormat()
- getPixels()
- getPlayer()
- getPosition()
- getSpeed()
- getTexture()
- getTexturePlanes()
- getTotalNumFrames()
- getWidth()
- isFrameNew()
- isInitialized()
- isLoaded()
- isPaused()
- isPlaying()
- isUsingTexture()
- load()
- loadAsync()
- nextFrame()
- play()
- previousFrame()
- setAnchorPoint()
- setFrame()
- setLoopState()
- setPaused()
- setPixelFormat()
- setPlayer()
- setPosition()
- setSpeed()
- setUseTexture()
- setVolume()
- stop()
- unbind()
- update()
Extends
This class extends others, you can call their methods on an instance of ofVideoPlayer too:
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 ofVideoPlayer::bind()
Documentation from code comments
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 ofVideoPlayer::close()
Documentation from code comments
Closes the movie file releases its resources.
This is an alias for closeMovie().
See also: closeMovie()
closeMovie()
void ofVideoPlayer::closeMovie()
Example:
ofVideoPlayer myPlayer;
myPlayer.loadMovie("myMovie.mov"); //Loads video resources
myPlayer.closeMovie(); //Unloads video resources
Documentation from code comments
Closes the movie file and releases its resources.
This is an alias for close().
See also: close()
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.
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).
getDuration()
float ofVideoPlayer::getDuration()
The getDuration() method returns a float value with the duration in seconds of the movie.
getMoviePath()
string ofVideoPlayer::getMoviePath()
Documentation from code comments
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.
getPixels()
ofPixels & ofVideoPlayer::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];
getPlayer()
shared_ptr< ofBaseVideoPlayer > ofVideoPlayer::getPlayer()
Documentation from code comments
Get a pointer to the internal video player implementation.
This returns a pointer to the ofBaseVideoPlayer interface. For
implementation-specfic features, this can be cast to the subtype
using dynamic_cast
Returns: A pointer to the internal video player implementation.
getPlayer()
const shared_ptr< ofBaseVideoPlayer > ofVideoPlayer::getPlayer()
Documentation from code comments
Get a const pointer to the internal video player implementation.
This returns a pointer to the ofBaseVideoPlayer interface. For
implementation-specfic features, this can be cast to the subtype
using dynamic_pointer_cast
Returns: A const pointer to the internal video player implementation.
getPlayer()
shared_ptr< PlayerType > ofVideoPlayer::getPlayer()
Documentation from code comments
Get a pointer to the internal video player implementation.
Calling getPlayer
Returns: A pointer to the internal video player implementation or nullptr if the cast fails.
getPlayer()
const shared_ptr< PlayerType > ofVideoPlayer::getPlayer()
Documentation from code comments
Get a const pointer to the internal video player implementation.
Calling getPlayer
Returns: A const pointer to the internal video player implementation or nullptr if the cast fails.
getPosition()
float ofVideoPlayer::getPosition()
The getPosition() method returns a float value between 0 and 1 with the relative position in the movie. A return value of 0 means the start point in the movie, a return value of 1 means the end of the movie.
Example:
void main() {
myPlayer.load("movies/fingers.mov");
}
void update() {
myPlayer.update();
}
void draw() {
ofLogNotice() << "The movie is playing the " << (myPlayer.getPosition() * 100) << "%";
ofLogNotice() << "The movie is in the following time in secs: " << myPlayer.getPosition()*myPlayer.getDuration();
}
isFrameNew()
bool ofVideoPlayer::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
}
isLoaded()
bool ofVideoPlayer::isLoaded()
Whether the resources that you've tried to load into your ofVideoPlayer have been loaded yet.
setAnchorPoint(...)
void ofVideoPlayer::setAnchorPoint(float x, float y)
Sets anchor points for this ofVideoPlayer instance.
setLoopState(...)
void ofVideoPlayer::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.
setPixelFormat(...)
bool ofVideoPlayer::setPixelFormat(ofPixelFormat pixelFormat)
OSX: Choose from OF_PIXELS_RGB or OF_PIXELS_RGBA
setPlayer(...)
void ofVideoPlayer::setPlayer(shared_ptr< ofBaseVideoPlayer > newPlayer)
Documentation from code comments
Set the internal video player implementation.
Advanced users may find it useful to set a custom internal video player implementation. The custom video player must implment the ofBaseVideoPlayer interface.
Parameters:
newPlayer Shared pointer to the new video player that extends from ofBaseVideoPlayer.
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.
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");
unbind()
void ofVideoPlayer::unbind()
Documentation from code comments
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 ofVideoPlayer::update()
Documentation from code comments
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().
Last updated 星期二, 19 十一月 2024 17:24:36 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue