Masking Video with Image: RandomVideoSlitScan

I have worked on this problem for quite awhile, and can't seam to find much about it on forums. I am trying to create a random slit scan process on a video signal using a one pixel line that scrubs across frame. I've tried using mask() techniques, and have had some success, but I can't get to look like I want it to. I want the line to show current time/frames and replace old frames that stay as stills, creating layered up layers of time.

        import processing.video.*;
        Movie myMovie;
        PImage maskImage;
        float randomX = 0.;

        void setup() {
          size(720, 480);
          background(0);
          myMovie = new Movie(this, "tennis.mov");
          myMovie.loop();
          maskImage = loadImage("mask.png");
          //maskImage.mask(myMovie);
          //myMovie.mask(maskImage);
          smooth();
        }

        void draw() {
          //background(0);
          randomX = random(720);
          maskImage.mask(myMovie);
          //myMovie.mask(maskImage);
          //image(myMovie, 0, 0);
          image(maskImage, randomX, 0);
          //fill(255);
          //noStroke();
          //rect(randomX, 0, 10, height);
        }

        void movieEvent(Movie m) {
          m.read();
        }  

VideoLinkDownload: https://db.tt/2uPvghk1mask

Answers

  • Answer ✓

    Answer to my own question:

     import processing.video.*;
        Shape shape;
        float rateX = 0;
        float rateY = 0;
        Movie myMovie;
        PGraphics gBuffer;
    
        void setup() {
          size(1920,1080);
          smooth();
    
          myMovie = new Movie(this, "1.mov");
          myMovie.loop();
          shape = new Shape(width/2, height/2, 100,height+500);
          gBuffer = createGraphics(width, height);
          background(0);
        }
    
        void draw() {
          //background(0);
          shape.display();
          shape.move(rateX, rateY);
          shape.wrap();
          myMovie.mask(gBuffer);
          image(myMovie, 0, 0);
          saveFrame();
        }
    
        void keyPressed () {
          if (key == CODED) {
            if (keyCode == UP) {
              rateY-=1;
            } else if (keyCode == DOWN) {
              rateY+=1;
            } else if (keyCode == LEFT) {
              rateX-=1;
            } else if (keyCode == RIGHT) {
              rateX+=1;
            }
          }
        }
    
        void keyReleased() {
          if (key == CODED) {
            if (keyCode == UP || keyCode == DOWN) {
              rateY=rateY;
            } else if (keyCode == LEFT || keyCode == RIGHT) {
              rateX=rateX;
            }
          }
        }
    
        void movieEvent(Movie m) {
          m.read();
        }
        // -------------------
        class Shape {
    
          float x=100;
          float y=240;
          float w=50;
          float h=50;
          float driftXspeed;
          float driftYspeed; 
    
          Shape(float tempX, float tempY, float tempW, 
          float tempH) {
            x = tempX;
            y = tempY;
            w = tempW;
            h = tempH;
            driftXspeed = 2;
            driftYspeed = 2;
          }
    
          void display() {
            float f = random(width);
            float g = random(height);
            gBuffer.beginDraw();
            gBuffer.background(0); 
            gBuffer.fill(255);
            gBuffer.noStroke();
            gBuffer.rectMode(CENTER);
            gBuffer.rect(x,y, w, h);
            gBuffer.endDraw();
          }
    
          void move(float xRate, float yRate) {
            x+=xRate;
            y+=yRate;
          }
    
          void wrap() {
            // Wrap Around Drifts
            if (x > width+w/2) {
              x=0-w/2;
            }
            if (x < 0-w/2) {
              x=width+w/2;
            }
    
            if (y < 0-w/2) {
              y=height+w/2;
            }
            if (y > height+w/2) {
              y=0-w/2;
            }
          }
        }
    
Sign In or Register to comment.