# Self-rulling video reader

**URL:** <https://discourse.processing.org/t/self-rulling-video-reader/6392>\
**Category:** Libraries\
**Created:** [December 7, 2018, 12:08pm UTC](https://discourse.processing.org/t/self-rulling-video-reader/6392 "2018-12-07T12:08:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thias](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thias](https://discourse.processing.org/u/thias)\
**Post date:** [December 7, 2018, 12:08pm UTC](https://discourse.processing.org/t/self-rulling-video-reader/6392/1 "2018-12-07T12:08:47Z")

</div>

Hello everyone !

I have a complex question and i can’t find any answer.  
I’m trying to make a code that capture a video with webcam when you click on a specific place and create a video in data when you stop the recording. And i want this video to be “loadable” in the same code.

To be more specific :  
what i have :  
I created a “folder” and when you click on it, a (closable) window pop with the capture.  
what i want :  
When you close the window i want it to create a new folder which will lead to a second window with the fresh-taken video (or an array of images, i don’t need sound or good motion quality). I would be pleased if it can be done an infinite time (each time you load the capture again it create a new folder) but i would be satisfied if it work for one time already.

THAT’S MY CODE :

```
import processing.video.*;
boolean saveRecord = false;
int fenCap =0;
int fenCapX ;
int fenCapY;
int fichCapX;
int fichCapY;
Capture capture;
void setup()
{
 capture = new Capture(this);
 capture.start();
}
void movieEvent(Movie m)
{
  m.read();
}
void draw()
{
//folder
rect(fichCapX, fichCapY, 60, 80);

//window
  if (fenCap==1)
  {
    strokeWeight(5);
    stroke(0);
    fill(255);
    rect(fenCapX, fenCapY, 580, 300);
    rect(fenCapX, fenCapY, 580, 30);
    rect(fenCapX, fenCapY, 30, 30);
    line(fenCapX+6, fenCapY+6, fenCapX+24, fenCapY+24);
    line(fenCapX+6, fenCapY+24, fenCapX+24, fenCapY+6);

    capture.read();
    image(capture, fenCapX+2, fenCapY+32, 576, 266);
  }
}

void mouseClicked()
{
//open capture
if (mouseX>fichCapX && mouseX<fichCapX+60 && mouseY>fichCapY && mouseY<fichCapY+150)
  {
    fenCap=1;
    saveRecord=true;
  }
  //close capture(5)
  if (fenCap==1 && mouseX>fenCapX && mouseX<fenCapX+30 && mouseY>fenCapY && mouseY<fenCapY+30)
  {
    fenCap=0;
    saveRecord=false;
  }

```

THAT’S WHAT I TRIED WITH IMAGES LIST :  
(not working because he expect to find the folder in data)

```
import processing.video.*;
boolean saveRecord = false;
PImage[] voyeurX ;
int fenCap =0;
int fenPlus =0;

int fenCapX ;
int fenCapY;
int fichCapX;
int fichCapY;

Capture capture;
int Voyeur=0;
int VoyeurCount=0;
float fichPlusX= random(1180);
float fichPlusY= random(600);
float fenPlusX= random(780);
float fenPlusY= random(400);

void setup()
{
 capture = new Capture(this);
  capture.start();

voyeurX=new PImage[200];
  for (int i=0; i<0x200; i++)
  {
    voyeurX[i]=loadImage("voyeur0/voyeur_"+i+".png");
  }
}

void movieEvent(Movie m)
{
  m.read();
}

void draw()
{
//folder
rect(fichCapX, fichCapY, 60, 80);

  if (Voyeur==1)
  {
     rect( fichPlusX, fichPlusY , 60, 80);
  }

//window
  if (fenCap==1)
  {
    strokeWeight(5);
    stroke(0);
    fill(255);
    rect(fenCapX, fenCapY, 580, 300);
    rect(fenCapX, fenCapY, 580, 30);
    rect(fenCapX, fenCapY, 30, 30);
    line(fenCapX+6, fenCapY+6, fenCapX+24, fenCapY+24);
    line(fenCapX+6, fenCapY+24, fenCapX+24, fenCapY+6);

    capture.read();
    image(capture, fenCapX+2, fenCapY+32, 576, 266);
  }

  if (fenPlus==1)
  {
    strokeWeight(5);
    stroke(0);
    fill(255);
    rect(fenPlusX, fenPlusY, 580, 300);
    rect(fenPlusX, fenPlusY, 580, 30);
    rect(fenPlusX, fenPlusY, 30, 30);
    line(fenPlusX+6, fenPlusY+6, fenPlusX+24, fenPlusY+24);
    line(fenPlusX+6, fenPlusY+24, fenPlusX+24, fenPlusY+6);

    image(voyeurX[0000],fen4X+2, fen4Y+32, 576, 266);
 }
   if (saveRecord == true) 
   {
     saveFrame("data/voyeur" +VoyeurCount+"/voyeur_###.png");
     println(VoyeurCount);
   }
}

void mouseClicked()
{
//open capture
if (mouseX>fichCapX && mouseX<fichCapX+60 && mouseY>fichCapY && mouseY<fichCapY+150)
  {
    fenCap=1;
    saveRecord=true;
Voyeur=1;
  }
  //close capture(5)
  if (fenCap==1 && mouseX>fenCapX && mouseX<fenCapX+30 && mouseY>fenCapY && mouseY<fenCapY+30)
  {
    fenCap=0;
    saveRecord=false;
Voyeur=0;
  }

```

I’m new in this forum, english is not my mother language and even if i use processing a bit i’m not very used to programing, so don’t hesitate to give me tips that you find obvious, they won’t necessarely be for me !

Thanks !

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [December 8, 2018, 3:49pm UTC](https://discourse.processing.org/t/self-rulling-video-reader/6392/2 "2018-12-08T15:49:31Z")

</div>

Hi! I’ll help with two issues:

1. If you are declaring functions (like `setup`, `movieEvent`, etc) it’s not allowed to have code outside function declarations, but you have a `for` loop near the beginning of your program. That for-loop should be inside setup, otherwise the program will not run.

2. Numbers that start with 0 are [octal](https://en.wikipedia.org/wiki/Octal) and if they start with 0x they are [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal). So

```auto
println(0200, 0x200);

```

will print

```auto
128, 512

```

I guess you want those two numbers to be equal, right? How many images do you want? 200? 128? 512?

---

<div class="post-metadata">

**Author:** ![thias](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thias](https://discourse.processing.org/u/thias)\
**Post date:** [December 9, 2018, 5:17pm UTC](https://discourse.processing.org/t/self-rulling-video-reader/6392/3 "2018-12-09T17:17:38Z")

</div>

hi thanks ! i missclicked when i paste this line, it was in setup but it still not working !  
Actually i put 200 thinking about a high number, i don’t need a special number, just one that will be enought to make a 10 second long animation.  
And thanks, i didn’t know about the hexadecimal stuff, i will change it for 200.

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [December 9, 2018, 5:38pm UTC](https://discourse.processing.org/t/self-rulling-video-reader/6392/4 "2018-12-09T17:38:00Z")

</div>

I made something inspired by your question. Sorry it’s not an answer, but maybe it’s somehow useful? 🙂

```auto
import processing.video.*;

Capture cam;
int x, y;

void setup() {
  size(640, 480);
  background(0);
  String[] cameras = Capture.list();
  cam = new Capture(this, cameras[0]);
  cam.start();
}

void draw() {
  if (cam.available()) {
    cam.read();
  }
  image(cam, x, y, 128, 96);
}

void mousePressed() {
  x = (mouseX / 128) * 128;
  y = (mouseY / 96) * 96;
}

```

---

<div class="post-metadata">

**Author:** ![thias](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thias](https://discourse.processing.org/u/thias)\
**Post date:** [December 12, 2018, 7:42am UTC](https://discourse.processing.org/t/self-rulling-video-reader/6392/5 "2018-12-12T07:42:54Z")

</div>

Hi, thanks you for this ! it gives me ideas to change my project a bit 🙂
