I need to import a video (.mp4) file and store it in a BufferedImage [], so I can work with each frame as if it were an image. my code (the part with (???) is where I did not conceive):
public class Main {
public static void main(String[] args) {
videoChromaKey(new File("./mascara.mp4"),new File("./fundo.mp4"),new Color(0,255,0),100);
}
public static BufferedImage chromaKey(BufferedImage bimg,BufferedImage bbg,Color key,int sensibility){
for(int i=0;i<bimg.getWidth();i++){
for(int j=0;j<bimg.getHeight();j++){
Color e=new Color(bimg.getRGB(i, j));
Color bgc=new Color(bbg.getRGB(i, j));
if(e.getGreen()-e.getRed()>=key.getGreen()-key.getRed()-sensibility && e.getGreen()-e.getRed()<=key.getGreen()-key.getRed()+sensibility &&
e.getGreen()-e.getBlue()>=key.getGreen()-key.getBlue()-sensibility && e.getGreen()-e.getBlue()<=key.getGreen()-key.getBlue()+sensibility
)
bimg.setRGB(i, j, bgc.getRGB());
}
}
return bimg;
}
}
public static void videoChromaKey(File in,File bg,File out,Color key,int sensibility){
BufferedImage[] vin= (???);
BufferedImage[] vbg= (???);
for(int i=0;i<vin.length && i<vbg.length;i++){
vin[i]=chromaKey(vin[i],vbg[i],key,sensibility);
}
//Gravar vin em arquivo out
(???)
}
}