Thanks for the code, it works for me. I wanted to take it one step further and generate a movie with an alpha channel. The animation codec supports this but so far it doesn't seem to work. Any ideas?
Code:
import processing.video.*;
MovieMaker mm;
PGraphics alphaImage;
int startFrame = 1; //set this..
int endFrame = 112;//.. this..
String fileNamePrefix = "frame-" ; //.. and this (example for "frame-1234.png or frame-0001.png"
String fileTypeSuffix = ".png" ;
//note this is setup for png but anything I think tiffs are supported too (jpgs work as well but contain no alpha info)
PImage img;
int currentFrame;
void setup()
{
size(512, 200); //..oh yeah and this - frame size goes here
colorMode(HSB,255);
currentFrame=startFrame-1;
mm = new MovieMaker(this, width, height, "imageSequencedMovie.mov", 24, MovieMaker.ANIMATION, MovieMaker.HIGH,24); //24
}
void draw()
{
currentFrame++;
image(loadImage(fileNamePrefix+ nf(currentFrame,4) +fileTypeSuffix), 0, 0, width, height);
alphaImage = createGraphics(width, height, P2D);//frame size could be set here too (including shrinking expanding etc)
alphaImage.beginDraw();
loadPixels();
alphaImage.loadPixels();
float h,s,b;
for (int i=0; i<pixels.length; i++)
{
h=hue(pixels[i]);
s=saturation(pixels[i]);
b=brightness(pixels[i]);
if (b>0) alphaImage.pixels[i]=color(h,s,b,255);
else alphaImage.pixels[i]=color(h,s,b,0);
// re-use the brightness value as the alpha --
// (since the pixel array, strictly speaking,
// does not contain alpha values (whoops.)
// in this example, if the brightness is 0,
// use 0 alpha, otherwise use full alpha.
}
alphaImage.updatePixels();
alphaImage.endDraw();
println(fileNamePrefix+"_alpha"+ nf(currentFrame,4) +fileTypeSuffix);
//mm.addFrame();
mm.addFrame(alphaImage.pixels,width,height); //save movie
//alphaImage.save(fileNamePrefix+"_alpha"+ nf(currentFrame,4) +fileTypeSuffix); //save individual frames
if(currentFrame==endFrame)
{
println("done");
mm.finish();
exit();
}
}