openFrameworks 007 - video

39,835 views

Published on

openFrameworks 007 - video

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
39,835
On SlideShare
0
From Embeds
0
Number of Embeds
33,523
Actions
Shares
0
Downloads
184
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • openFrameworks 007 - video

    1. 1. openFrameworks Video
    2. 2. ofVideoPlayeropenFrameworks allows you to easily displayvideos from file or grab a video stream from awebcam. For playing videos from file you useofVideoPlayer to grab video from your webcam youuse ofVideoGrabber. The ofVideoPlayer class looksfollows the same API as ofSoundPlayer whichmakes it really easy to work with video and sound.
    3. 3. Playing a videoTo playback a video you create a ofVideoPlayermember and call loadMovie to load a movie fromdisk. Call play to start playing the movie. IntestApp::update you need to update the playhead forthe video player as well by calling update on yourofVideoPlayer object.testApp.h testApp.cppclass testApp : public ofBaseApp{ void testApp::setup(){ public: my_video.loadMovie("fingers.mov"); ofVideoPlayer my_video; my_video.play();} } void testApp::draw(){ my_video.draw(10,10); }
    4. 4. Playing a videoTo playback a video you create a ofVideoPlayermember and call loadMovie to load a movie fromdisk. Call play to start playing the movie. IntestApp::update you need to update the playhead forthe video player as well by calling update on yourofVideoPlayer object.testApp.h testApp.cppclass testApp : public ofBaseApp{ void testApp::setup(){ public: my_video.loadMovie("fingers.mov"); ofVideoPlayer my_video; my_video.play();} } void testApp::draw(){ my_video.draw(10,10); }
    5. 5. Scrubbing through videoUsing nextFrame and previousFrame you can scrubthrough a paused movie.testApp.h testApp.cpp void testApp::setup(){ ofBackground(33);class testApp : public ofBaseApp{ my_video.loadMovie("fingers.mov"); public: my_video.play(); ofVideoPlayer my_video; }} void testApp::update(){ my_video.update(); } void testApp::draw(){ my_video.draw(0,0); } void testApp::keyPressed(int key){ if(key == p) { my_video.setPaused(true); } else if(key == a) { my_video.nextFrame(); } else if(key == b) { my_video.previousFrame(); } }
    6. 6. Getting pixelsCheck if the player has a new frame usingisFrameNew, then use getPixels to retrieve the newpixels.testApp.h testApp.cpp void testApp::setup(){class testApp : public ofBaseApp{ ofBackground(33); public: my_video.loadMovie("fingers.mov"); ofVideoPlayer my_video; my_video.play(); ofImage my_video_frame; } // tell our image how many/what pixels it will store. my_video_frame.allocate( my_video.getWidth() ,my_video.getHeight() ,OF_IMAGE_COLOR ); } void testApp::update(){ my_video.update(); if(my_video.isFrameNew()) { // copy the pixels from the new video frame. my_video_frame.setFromPixels( my_video.getPixels() ,my_video.getWidth() ,my_video.getHeight() ,OF_IMAGE_COLOR ); } }
    7. 7. Controlling playbackYou can change the playhead position usingsetPosition(float). A value of 0.0 means go to thestart, 1.0 go to the end. Change the speed usingsetSpeed(float). A speed of 0.0 is the same aspausing the video, values above 1.0 are faster thenthe default playback speed. Of course you can usefirstFrame() to jump to the first frame. WithsetPaused(bool) you can pause or continue playback.When you want to jump to a specific frame usesetFrame(int). Check the total number of frames withgetTotalNumFrames()
    8. 8. ofVideoPlayerbool loadMovie(string fileName)void close()void play()void update()void stop()bool isFrameNew()unsigned char* getPixels()ofPixelsRef getPixelsRef()float getPosition()float getSpeed()float getDuration()bool getIsMovieDone()
    9. 9. ofVideoPlayervoid setPosition()void setVolume(int volume)void setLoopState(ofLoopType state)int getLoopState()void setSpeed(float speed)void setFrame(int frame)void setUseTexture(bool use)ofTexture& getTextureReference()void draw(float x, float y, float w, float h)void draw(float x, float y)void draw(const ofPoint& p)void draw(const ofRectangle& r)
    10. 10. ofVideoPlayervoid setAnchorPercent(float xPct, float yPct)void setAnchorPoint(float x, float y)void resetAnchor()void setPaused(bool paused)int getCurrentFrame()int getTotalNumFrames()void firstFrame()void nextFrame()void previousFrame()float getWidth()float getHeight()bool isPaused()bool isPlaying()
    11. 11. ofVideoGrabberThe ofVideoGrabber grabs video from a webcam.The class is similar to ofVideoPlayer. Maindifference is that you need to tell what webcam(device) you want to use as source.
    12. 12. ofVideoGrabberGet a list of available devices. Make sure you first initialize the grabber using initGrabber. testApp.h class testApp : public ofBaseApp{ public: ofVideoGrabber my_grabber; } testApp.cpp void testApp::setup(){ my_grabber.initGrabber(320,240); my_grabber.listDevices(); }
    13. 13. ofVideoGrabber Draw video to screen! testApp.cpp void testApp::setup(){ my_grabber.initGrabber(320,240); my_grabber.setDeviceID(1); } void testApp::update(){ my_grabber.update(); } void testApp::draw(){ my_grabber.draw(0,0); }
    14. 14. ofVideoGrabberWhen you want to grab pixels from your webcamyou can use the function getPixels. Though youneed to check if we got a new frame usingisFrameNew because you don’t want to get thesame pixels we already have. void testApp::update(){ my_grabber.update(); if(my_grabber.isFrameNew()) { unsigned char* pix = my_grabber.getPixels(); } }
    15. 15. ofVideoGrabbervoid listDevices()bool isFrameNew()void update()void close()void initGrabber(int w, int h)bool initGrabber(int w, int h, bool texture)void videoSettings()unsigned char* getPixels()ofPixelsRef& getPixelsRef()ofTexture& getTextureReference()void setVerbose(bool verbose)void setDeviceID(int device)
    16. 16. ofVideoGrabbervoid setUseTexture(bool use)void draw(float x, float y, float w, float h)void draw(float x, float y)void draw(ofPoint& p)void draw(ofRectangle& r)void setAnchorPercent(float xPct, float yPct)void setAnchorPoint(float x, float y)float getWidth()float getHeight()
    17. 17. ofVideoGrabberofLoopType - used for ofSetLoopStateOF_LOOP_NONEOF_LOOP_PALINDROMEOF_LOOP_NORMAL
    18. 18. roxluwww.roxlu.com

    ×