brik
YaBB Newbies
Offline
Posts: 23
Close Movie file so it can be deleted.
Mar 25th , 2009, 10:05pm
Hi there, i'm trying to make a sketch that appends recorded frames to the end of an existing movie, but when I go to delete the original movie after reading the frames from it (so I can save the new movie with the same filename), the delete fails because the file is still in use (even though it has stopped playing). Is there some way to close the file so it can be deleted? Heres the source. import processing.video.*; MovieMaker mm; Capture cam; Movie oldMovie; PImage[] newFrames; boolean doneReading=true; String path; File f; void setup() { size(320, 240); frameRate(30); newFrames=new PImage[0]; cam = new Capture(this, 320, 240); path=dataPath("rec.mov"); f=new File(path); if(f.exists()){ oldMovie = new Movie(this,path,30); oldMovie.play(); oldMovie.speed(1); doneReading=false; } textFont(createFont("Arial",16),16); background(160, 32, 32); } void draw() { if (cam.available()&& doneReading){ cam.read(); cam.loadPixels(); PImage img=createImage(cam.width,cam.height,ARGB); img.loadPixels(); arrayCopy(cam.pixels,img.pixels); newFrames=(PImage[])append(newFrames,img); image(cam, 0, 0,width,height); text("Finished reading.",10,20); } } void movieEvent(Movie oldMovie) { if(oldMovie.time()==oldMovie.duration()){ doneReading=true; oldMovie.stop(); } else{ oldMovie.read(); oldMovie.loadPixels(); PImage img=createImage(oldMovie.width,oldMovie.height,ARGB); img.loadPixels(); arrayCopy(oldMovie.pixels,img.pixels); newFrames=(PImage[])append(newFrames,img); } } void keyPressed() { if (key == ' ') { println(f.delete()); mm = new MovieMaker(this, width, height, path, 30, MovieMaker.ANIMATION, MovieMaker.HIGH); for(int i=0;i<newFrames.length;i++){ image(newFrames[i],0,0,width,height); mm.addFrame(); } mm.finish(); exit(); } }