Skip to content

Instantly share code, notes, and snippets.

@moebiussurfing
Last active February 11, 2020 08:51
Show Gist options
  • Save moebiussurfing/36ac5263dba66e601d46eb5d1985d748 to your computer and use it in GitHub Desktop.
Save moebiussurfing/36ac5263dba66e601d46eb5d1985d748 to your computer and use it in GitHub Desktop.
openFrameworks - open file system dialog // get texture from video
https://forum.openframeworks.cc/t/how-do-i-mix-the-alpha-channel-of-one-video-with-another/18771
ofApp.h file
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofVideoPlayer video, maskVideo;
bool bVideosLoaded = false;
};
ofApp.cpp file:
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
auto r = ofSystemLoadDialog("Select video file"); // use the load dialog to find the video on your
//computer. if you already know the path and/or dont want to have the load dialog popping up just
//manually specify the file path to the video file.
if(r.bSuccess){
bVideosLoaded = video.load(r.getPath());
cout << r.getPath() << endl; // just print the video path.
}
if(bVideosLoaded){
r = ofSystemLoadDialog("Select masking video file");
if(r.bSuccess){
bVideosLoaded = maskVideo.load(r.getPath());
cout << r.getPath() << endl;
}
}
if(bVideosLoaded){ //Checking that both videos loaded properly
video.play();
maskVideo.play();
}
}
//--------------------------------------------------------------
void ofApp::update(){
if(bVideosLoaded){
video.update();
maskVideo.update();
if(video.isFrameNew() || maskVideo.isFrameNew()){
video.getTexture().setAlphaMask(maskVideo.getTexture()); // THIS IS THE MAGIC LINE!
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
if(bVideosLoaded){
video.draw(0,0);
maskVideo.draw(video.getWidth(), 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment