Movie.width and movie.length do not always work depending on movie

I have two movies: mov1 and mov2.
If I run the following code in draw() by selecting mov1, everything works fine *at every launch". Instead, if I run it by selecting mov2, I sometimes get the error “Width (0) and height (0) cannot be <= 0”.

In other words, with mov1, the code is able to always retrieve the correct width and height before running the following lines. With mov2, the code is not always able to retrieve the correct width and height. Anybody knows why? Are there specific movie formats that are recommended for Ubuntu?

void magicWindow(Movie mov, String wnd_type, float[] wnd_size, float[] init_pos, float offset, float wnd_transparency, float wnd_amp) 
{
  // wnd_type can be "vrt" for vertical, "hrz" for horizontal, "rect" for rectangle, or "circ" for circles.
  // when "vrt" is selected, the image randomly moves only on the x_axis; when "hrz", only on the y axis, when "rect" or "circ" the image move randomly everywhere.
  // "rect" asks for width and height of the rectange, while "circle" asks for a center point and a ray.
  // param1 is width, param2 is height. vrt_amp takes a value between 0 and 1.
  // int time = millis();
  float pos_x = init_pos[0]; float pos_y = init_pos[1]; // hels reading the code below 
  float param1 = wnd_size[0]; float param2 = wnd_size[1];
  if(!((wnd_type == "vrt") || (wnd_type == "hrz") || (wnd_type == "rect") || (wnd_type == "circ"))) 
  {  
    println("window type can be either vrt, hrz, rect or circ.");
  }
  else {
    if (wnd_type == "vrt") { param1 = param1 * wnd_amp; pos_y = 0 + offset; }
    if (wnd_type == "hrz") { param2 = param2 * wnd_amp; pos_x = 0 + offset; }
    if (wnd_type == "rect" || wnd_type == "circ") { param1 = param1 * wnd_amp; param2 = param2 * wnd_amp; pos_x = pos_x + offset; pos_y = pos_y + offset; }  
    video_temp = mov.copy();
    println(mov.width); println(mov.height);
    PGraphics wnd_img = createGraphics(mov.width, mov.height);
    wnd_img.beginDraw();
    wnd_img.background(0);
    
    for(int i = 0; i < wnd_amp; i++) {
      if (wnd_type == "vrt") { wnd_img.translate(pos_x - param1/2, pos_y); } // y_axis remains constant
      if (wnd_type == "hrz") { wnd_img.translate(pos_x, pos_y - param2/2); } // x_axis remains constant
      if (wnd_type == "rect" || wnd_type == "circ") { wnd_img.translate(pos_x - param1/2, pos_y - param2/2); } // refers to position of the center of the square or circle  
      wnd_img.fill(color(255, wnd_transparency*255));
      if((wnd_type == "vrt") || (wnd_type == "hrz") || (wnd_type == "rect")) {
        wnd_img.rect(0, 0, param1, param2);
      }
    }
    wnd_img.endDraw();
    video_temp.mask(wnd_img);
    image(video_temp, 0, 0);
  }
}

Hello @lucedan

Related:
OpenCV error in Processing 4.0b2 - #10 by glv
Problem with slitscan effect for pre-recorded video - #2 by GoToLoop

You can also add a break statement if you want a timeout in the while() loop.

Reference:

:)