my for-loop skips a position

edited November 2016 in Library Questions

i tried to adjust a slit scan video code to move the copy command from left to right through the video. that works, but in the output it skips a position, leaving a white strip between. how can i make the output dense?

import processing.video.*;
Movie myMovie;
int pos;
int sliceSize = 5;
int outputcounter= 1;
String date;
void setup() {
  size(5000, 720);
  myMovie = new Movie(this, "versuch1.mp4");
  myMovie.loop();
  pos = 0;
  date = timestamp();
  //myMovie.jump(176);
}
void draw() {
  if (myMovie.available()) {
    myMovie.read();
    pushMatrix();
    for (int i=0; i<1280; i+= sliceSize){
    //translate(width/2, height/2);
    //rotate(HALF_PI);
    //translate(-width/2, -height/2);
    //tint(255, 20);
    copy(myMovie, i, 0, sliceSize, myMovie.height, pos, 0, sliceSize, height); //(copy (quelle, x , y, breite, höhe, position im neuen bild, ))
    scale(-1,1);
    pos+=sliceSize*i; //horizontal gefilmt
    //copy(myMovie, 0, myMovie.height/2, myMovie.width, sliceSize, 0, pos, width, sliceSize); //vertical gefilmt
    //pos-=sliceSize;
    if (pos>width) {
      saveFrame("png/"+ date+"/"+nf(outputcounter,3)+".png");
      outputcounter++;
      pos = 0;
    }
    }
    //image(myMovie, 0,0,960,540);}
    popMatrix();
  }
  }


// Called every time a new frame is available to read
/**void movieEvent(Movie m) {
 m.read();
 }*/

void keyPressed() {
  if (key == 32) {
    saveFrame("png/output_"+timestamp()+".png");
  }
}

String timestamp() {
  return new java.text.SimpleDateFormat("yyyy_MM_dd_kkmmss").format(new java.util.Date ());
}

//webseite 100vh quadrat (3/4=133) png= 001.png, 002.png

Answers

  • edited November 2016

    nothing

  • Before you start working with s wider strip, try using the original example. Keep in mind you are using a screen width of 5000 pixels. And you are saving many frames. All these features are working but are irrelevant to your problem. Reduce your program to a minimum code that reproduces the error.

    Kf

  • edited November 2016

    hey, thank you. i worked on it a bit more. i got a friend to take a look at it. it is supposed to work i believe. but there are grey gaps in between the positions. i think it overjumps certain position, but it all seems wild to me.

    import processing.video.*;
    Movie myMovie;
    int pos;
    int sliceSize = 20;
    int outputcounter= 1;
    String date;
    void setup() {
      size(1280, 720);
      myMovie = new Movie(this, "leo.mp4");
      myMovie.loop();
      pos = 0;
      date = timestamp();
    }
    void draw() {
      if (myMovie.available()) {
        myMovie.read();
        int i=frameCount%1281*sliceSize;
        pushMatrix();
       copy(myMovie, i, 0, sliceSize, myMovie.height, i, 0, sliceSize, height)
        if (i>width) {
          saveFrame("png/"+ date+"/"+nf(outputcounter, 3)+".png");
          outputcounter++;
          pos = 0;
        }
        popMatrix();
      }
    }
    
  • edited November 2016 Answer ✓

    that assumes that a new movie frame is available every time draw is called. which i don't think is true.

    i think you need to get rid of the reliance on frameCount

    also, line 19 is missing a ;

  • Answer ✓

    int i=frameCount%1281*sliceSize;

    maths here is probably wrong also - you are going WAY off the screen - i might be 1280 * sliceSize. you probably want (width / sliceSize) instead of 1281. but this fix will break your condition in line 20...

  • edited November 2016

    hey koogs, thanks for looking at my script closely. i adjusted a lot of things. I tried to establish the framerate of the movie and of draw to 1. but it does not work. after 1/10th of the rendering, the movie is already over. i estamate, the movie plays in normal speed. do you know an option, how i can adjust the copy command with every frame read?

    there is also: i adjusted the sliceSize to the speed of the movement from left to right: width/total frames.

    import processing.video.*;
    Movie myMovie;
    int pos;
    int sliceSize = 3; // width/total frames
    int outputcounter= 1;
    String date;
    void setup() {
      size(1080, 850);
      myMovie = new Movie(this, "versuch3.mp4");
      myMovie.play();
      pos = 0;
      date = timestamp();
      myMovie.frameRate(1);
      frameRate(1);
      //myMovie.jump(176);
    }
    void draw() {
      if (myMovie.available()) {
        myMovie.read();
        int i=sliceSize*(frameCount%1280);
        pushMatrix();
        copy(myMovie, i, 0, sliceSize, myMovie.height, i, 0, sliceSize, height);
        if (i>width) {
          saveFrame("png/"+ date+"/"+nf(outputcounter, 3)+".png");
          outputcounter++;
          i= 0;
        }
        //image(myMovie, 0,0,960,540);
        popMatrix();
      }
    }
    
  • edited November 2016

    okey, got it. here is my latest update. i started using movieEvent, for controlling the scan on the x axis in relation to every frame. now i still have the problem of adjusting the speed of the video with the total number of frames in the video. so i reach the end of the canvas, when the movie ends. and also. sometimes it does not copy and in the output there is just a white bar.

    import processing.video.*;
    Movie myMovie;
    int pos;
    int sliceSize = 1;
    int outputcounter= 1;
    String date;
    boolean newFrame=false;
    void setup() {
      size(1080, 850);
      myMovie = new Movie(this, "versuch3.mp4");
      myMovie.loop();
      pos = 0;
      date = timestamp();
      myMovie.frameRate(24);
      frameRate(24);
    }
    void movieEvent(Movie myMovie){
      myMovie.read();
      newFrame=true;
    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    void draw() {
      if (newFrame) {
        pushMatrix();
        int i=sliceSize*(frameCount%1280);
        copy(myMovie, i, 0, sliceSize, myMovie.height, i, 0, sliceSize, height);
        popMatrix();
        newFrame=false;
             if (i>width) {
          saveFrame("png/"+ date+"/"+nf(outputcounter, 3)+".png");
          outputcounter++;
          i=0;
        }  
    }
    }
    
Sign In or Register to comment.