SlideShare uma empresa Scribd logo
1 de 18
openFrameworks
      Video
ofVideoPlayer

openFrameworks allows you to easily display
videos from file or grab a video stream from a
webcam. For playing videos from file you use
ofVideoPlayer to grab video from your webcam you
use ofVideoGrabber. The ofVideoPlayer class looks
follows the same API as ofSoundPlayer which
makes it really easy to work with video and sound.
Playing a video
To playback a video you create a ofVideoPlayer
member and call loadMovie to load a movie from
disk. Call play to start playing the movie. In
testApp::update you need to update the playhead for
the video player as well by calling update on your
ofVideoPlayer object.


testApp.h                           testApp.cpp
class 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);
                                    }
Playing a video
To playback a video you create a ofVideoPlayer
member and call loadMovie to load a movie from
disk. Call play to start playing the movie. In
testApp::update you need to update the playhead for
the video player as well by calling update on your
ofVideoPlayer object.


testApp.h                           testApp.cpp
class 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);
                                    }
Scrubbing through video
Using nextFrame and previousFrame you can scrub
through 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();
                                     
   }
                                     }
Getting pixels
Check if the player has a new frame using
isFrameNew, then use getPixels to retrieve the new
pixels.

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
                                     
   
     );
   
                                     
   }
                                     }
Controlling playback
You can change the playhead position using
setPosition(float). A value of 0.0 means go to the
start, 1.0 go to the end. Change the speed using
setSpeed(float). A speed of 0.0 is the same as
pausing the video, values above 1.0 are faster then
the default playback speed. Of course you can use
firstFrame() to jump to the first frame. With
setPaused(bool) you can pause or continue playback.
When you want to jump to a specific frame use
setFrame(int). Check the total number of frames with
getTotalNumFrames()
ofVideoPlayer
bool 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()
ofVideoPlayer
void 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)
ofVideoPlayer
void 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()
ofVideoGrabber

The ofVideoGrabber grabs video from a webcam.
The class is similar to ofVideoPlayer. Main
difference is that you need to tell what webcam
(device) you want to use as source.
ofVideoGrabber
Get 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();
                }
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);
  }
ofVideoGrabber
When you want to grab pixels from your webcam
you can use the function getPixels. Though you
need to check if we got a new frame using
isFrameNew because you don’t want to get the
same pixels we already have.



        void testApp::update(){
        
 my_grabber.update();
        
 if(my_grabber.isFrameNew()) {
        
 
      unsigned char* pix = my_grabber.getPixels();
        
 }
        }
ofVideoGrabber
void 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)
ofVideoGrabber
void 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()
ofVideoGrabber
ofLoopType - used for ofSetLoopState

OF_LOOP_NONE

OF_LOOP_PALINDROME

OF_LOOP_NORMAL
roxlu
www.roxlu.com

Mais conteúdo relacionado

Mais procurados

A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
Chu Lam
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
vidyamittal
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
jeffz
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
Giordano Scalzo
 

Mais procurados (20)

A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
Design pattern part 2 - structural pattern
Design pattern part 2 - structural patternDesign pattern part 2 - structural pattern
Design pattern part 2 - structural pattern
 
Computer Vision using Ruby and libJIT - RubyConf 2009
Computer Vision using Ruby and libJIT - RubyConf 2009Computer Vision using Ruby and libJIT - RubyConf 2009
Computer Vision using Ruby and libJIT - RubyConf 2009
 
Getting started with open cv in raspberry pi
Getting started with open cv in raspberry piGetting started with open cv in raspberry pi
Getting started with open cv in raspberry pi
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
Open cv tutorial
Open cv tutorialOpen cv tutorial
Open cv tutorial
 
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему кодуITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
 
Антон Бикинеев, Writing good std::future< C++ >
Антон Бикинеев, Writing good std::future< C++ >Антон Бикинеев, Writing good std::future< C++ >
Антон Бикинеев, Writing good std::future< C++ >
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 63 of 196
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 

Semelhante a openFrameworks 007 - video

Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 

Semelhante a openFrameworks 007 - video (20)

Building a Native Camera Access Library - Part I.pdf
Building a Native Camera Access Library - Part I.pdfBuilding a Native Camera Access Library - Part I.pdf
Building a Native Camera Access Library - Part I.pdf
 
QA Fest 2019. Алексей Альтер-Песоцкий. Snapshot testing with native mobile fr...
QA Fest 2019. Алексей Альтер-Песоцкий. Snapshot testing with native mobile fr...QA Fest 2019. Алексей Альтер-Песоцкий. Snapshot testing with native mobile fr...
QA Fest 2019. Алексей Альтер-Песоцкий. Snapshot testing with native mobile fr...
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guice
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Building a Native Camera Access Library - Part III - Transcript.pdf
Building a Native Camera Access Library - Part III - Transcript.pdfBuilding a Native Camera Access Library - Part III - Transcript.pdf
Building a Native Camera Access Library - Part III - Transcript.pdf
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
Creating a Facebook Clone - Part XLIII - Transcript.pdf
Creating a Facebook Clone - Part XLIII - Transcript.pdfCreating a Facebook Clone - Part XLIII - Transcript.pdf
Creating a Facebook Clone - Part XLIII - Transcript.pdf
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Of class1
Of class1Of class1
Of class1
 
Moustamera
MoustameraMoustamera
Moustamera
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
Help with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docxHelp with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docx
 
Vue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyVue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapy
 
Ssaw08 1118
Ssaw08 1118Ssaw08 1118
Ssaw08 1118
 
Building a Native Camera Access Library - Part III.pdf
Building a Native Camera Access Library - Part III.pdfBuilding a Native Camera Access Library - Part III.pdf
Building a Native Camera Access Library - Part III.pdf
 
Building a Native Camera Access Library - Part V.pdf
Building a Native Camera Access Library - Part V.pdfBuilding a Native Camera Access Library - Part V.pdf
Building a Native Camera Access Library - Part V.pdf
 

openFrameworks 007 - video

  • 2. ofVideoPlayer openFrameworks allows you to easily display videos from file or grab a video stream from a webcam. For playing videos from file you use ofVideoPlayer to grab video from your webcam you use ofVideoGrabber. The ofVideoPlayer class looks follows the same API as ofSoundPlayer which makes it really easy to work with video and sound.
  • 3. Playing a video To playback a video you create a ofVideoPlayer member and call loadMovie to load a movie from disk. Call play to start playing the movie. In testApp::update you need to update the playhead for the video player as well by calling update on your ofVideoPlayer object. testApp.h testApp.cpp class 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. Playing a video To playback a video you create a ofVideoPlayer member and call loadMovie to load a movie from disk. Call play to start playing the movie. In testApp::update you need to update the playhead for the video player as well by calling update on your ofVideoPlayer object. testApp.h testApp.cpp class 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. Scrubbing through video Using nextFrame and previousFrame you can scrub through 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. Getting pixels Check if the player has a new frame using isFrameNew, then use getPixels to retrieve the new pixels. 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. Controlling playback You can change the playhead position using setPosition(float). A value of 0.0 means go to the start, 1.0 go to the end. Change the speed using setSpeed(float). A speed of 0.0 is the same as pausing the video, values above 1.0 are faster then the default playback speed. Of course you can use firstFrame() to jump to the first frame. With setPaused(bool) you can pause or continue playback. When you want to jump to a specific frame use setFrame(int). Check the total number of frames with getTotalNumFrames()
  • 8. ofVideoPlayer bool 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. ofVideoPlayer void 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. ofVideoPlayer void 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. ofVideoGrabber The ofVideoGrabber grabs video from a webcam. The class is similar to ofVideoPlayer. Main difference is that you need to tell what webcam (device) you want to use as source.
  • 12. ofVideoGrabber Get 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. 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. ofVideoGrabber When you want to grab pixels from your webcam you can use the function getPixels. Though you need to check if we got a new frame using isFrameNew because you don’t want to get the same pixels we already have. void testApp::update(){ my_grabber.update(); if(my_grabber.isFrameNew()) { unsigned char* pix = my_grabber.getPixels(); } }
  • 15. ofVideoGrabber void 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. ofVideoGrabber void 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. ofVideoGrabber ofLoopType - used for ofSetLoopState OF_LOOP_NONE OF_LOOP_PALINDROME OF_LOOP_NORMAL

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n