Skip to content

Instantly share code, notes, and snippets.

@jvcleave
Created July 7, 2014 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvcleave/cdaff9da3e1216f8ed1b to your computer and use it in GitHub Desktop.
Save jvcleave/cdaff9da3e1216f8ed1b to your computer and use it in GitHub Desktop.
VideoSource
#pragma once
#include "ofMain.h"
class VideoSource
{
public:
ofVideoGrabber camera;
ofVideoPlayer videoPlayer;
bool isCamera;
VideoSource()
{
isCamera = false;
}
void setup(int width, int height)
{
camera.initGrabber(width, height);
isCamera = true;
}
void setup(string videoPath)
{
videoPlayer.loadMovie(videoPath);
videoPlayer.play();
isCamera = false;
}
void update()
{
if(isCamera)
{
camera.update();
}else
{
videoPlayer.update();
}
}
bool isFrameNew()
{
bool isNew = false;
if(isCamera)
{
isNew = camera.isFrameNew();
}else
{
isNew = videoPlayer.isFrameNew();
}
return isNew;
}
ofBaseHasPixels& getSource()
{
if(isCamera)
{
return camera;
}else
{
return videoPlayer;
}
}
void draw(int x, int y)
{
if(isCamera)
{
camera.draw(x, y);
}else
{
videoPlayer.draw(x, y);
}
}
int getWidth()
{
int width = 0;
if(isCamera)
{
width = camera.getWidth();
}else
{
width = videoPlayer.getWidth();
}
return width;
}
int getHeight()
{
int height = 0;
if(isCamera)
{
height = camera.getHeight();
}else
{
height = videoPlayer.getHeight();
}
return height;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment