processing-video icon indicating copy to clipboard operation
processing-video copied to clipboard

Can't video pixels when using P3D

Open martoo6 opened this issue 5 years ago • 1 comments

Pixelate example will always load black colors on mov.get() when using P3D renderer on version 2.0-beta4 I found that rendering the Movie before reading the it makes it work as a workaround.

/**
 * Pixelate  
 * by Hernando Barragan.  
 * 
 * Load a QuickTime file and display the video signal 
 * using rectangles as pixels by reading the values stored 
 * in the current video frame pixels array. 
 */

import processing.video.*;

int numPixelsWide, numPixelsHigh;
int blockSize = 10;
Movie mov;
color movColors[];

void setup() {
  size(560, 406, P3D);
  noStroke();
  mov = new Movie(this, "launch2.mp4");
  mov.loop();
  numPixelsWide = width / blockSize;
  numPixelsHigh = height / blockSize;
  println(numPixelsWide);
  movColors = new color[numPixelsWide * numPixelsHigh];
}

// Display values from movie
void draw() {
  image(mov, 0, 0);
  if (mov.available() == true) {
    mov.read();
    mov.loadPixels();
    int count = 0;
    for (int j = 0; j < numPixelsHigh; j++) {
      for (int i = 0; i < numPixelsWide; i++) {
        movColors[count] = mov.get(i*blockSize, j*blockSize);
        count++;
      }
    }
  }

  background(255);
  for (int j = 0; j < numPixelsHigh; j++) {
    for (int i = 0; i < numPixelsWide; i++) {
      fill(movColors[j*numPixelsWide + i]);
      rect(i*blockSize, j*blockSize, blockSize, blockSize);
    }
  }

}

martoo6 avatar Apr 26 '20 22:04 martoo6

I found that you can also render the movie outside of the screen canvas and it also works.

image(mov, width, 0);

This can be useful when you need to not clear the background.

Anyway, this is not the way is supposed to work.

ludiccc avatar Jun 12 '20 21:06 ludiccc