<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with movieevent() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p2/feed.rss?Tag=movieevent%28%29</link>
      <pubDate>Sun, 08 Aug 2021 15:19:35 +0000</pubDate>
         <description>Tagged with movieevent() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedmovieevent%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Play video using Processing, Arduino and PIR Sensor</title>
      <link>https://forum.processing.org/two/discussion/25365/play-video-using-processing-arduino-and-pir-sensor</link>
      <pubDate>Sun, 03 Dec 2017 22:41:30 +0000</pubDate>
      <dc:creator>m4rdones</dc:creator>
      <guid isPermaLink="false">25365@/two/discussions</guid>
      <description><![CDATA[<p>Hi. A friend and I are in the middle of a video installation tests. I'm using an Arduino PIR Sensor and an Arduino Uno board.</p>

<p>I need to stop a video when the PIR is "On" (Detects motion) and to play that video if the PIR is "Off".</p>

<p>Checking the Processing and Arduino websites, examples and references I couldn't figured out what I'm doing wrong.
Please let me know if something is missing or left.
Thanks in advance for any help!</p>

<p>This is the Arduino Code (copied from Arduino and Processing communication tutorials found on the web):</p>

<pre><code>/*
   PIR sensor tester
*/

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
</code></pre>

<p>And here is the Processing code:</p>

<pre><code>import processing.serial.*;
import processing.video.*; 

Serial myPort;
String val;    

Movie video;

void setup() {
  size(640,480);
  video = new Movie(this,"sujeto1.mp4");
  video.loop();
  String portName = Serial.list()[0];
  myPort = new  Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void serialEvent (Serial myPort) {
  if (myPort.available() &gt; 0) {
    val=myPort.readStringUntil('\n');
  }
  if (val=="Motion detected!") {
    video.stop();
  } else {
    video.loop();
  }
  println(val);

}
void draw() {
  background(0);
  image(video,0,0);

} 

void movieEvent(Movie video) {
  video.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Help figuring out error when using Video library</title>
      <link>https://forum.processing.org/two/discussion/25428/help-figuring-out-error-when-using-video-library</link>
      <pubDate>Wed, 06 Dec 2017 22:35:41 +0000</pubDate>
      <dc:creator>NewTimer</dc:creator>
      <guid isPermaLink="false">25428@/two/discussions</guid>
      <description><![CDATA[<p>This is my code that is currently used to cycle through 3 different videos by pressing Q:</p>

<pre><code>import processing.video.*;
static final int movieCount = 3;
final Movie[] myMovie = new Movie[movieCount];
int index;
int maxMovieIndex = movieCount-1;

void setup() {
  size(1920, 1080);
  myMovie[0] = new Movie(this, "scene_0.mp4");
  myMovie[1] = new Movie(this, "scene_1.mp4");
  myMovie[2] = new Movie(this, "scene_2.mp4");
  myMovie[0].loop();
}

void draw() {
  set(0, 0, myMovie[index]);
  image(myMovie[index], 0, 0);

  println("index: " + index);
}

void keyPressed()
{
 if (key == 'q')
 {
   myMovie[index].pause();
   if (index != maxMovieIndex)
   {
    index++; 
   }
   else
   {
    index = 0; 
   }
   myMovie[index].loop();
 }
}

void movieEvent(Movie m) {
  m.read();
}
</code></pre>

<p>It runs, but if I exit after doing a switch, I get an error in the console upon exit:</p>

<blockquote class="Quote">
  <p>(java.exe:6620): GStreamer-CRITICAL **: 
  Trying to dispose element Movie Player, but it is in PAUSED instead of the NULL state.
  You need to explicitly set elements to the NULL state before
  dropping the final reference, to allow them to clean up.
  This problem may also be caused by a refcounting bug in the
  application or some element.</p>
  
  <p>(java.exe:6620): GStreamer-CRITICAL **: 
  Trying to dispose element inputselector0, but it is in PAUSED instead of the NULL state.
  You need to explicitly set elements to the NULL state before
  dropping the final reference, to allow them to clean up.
  This problem may also be caused by a refcounting bug in the
  application or some element.</p>
</blockquote>

<p>What does this mean, and how do I fix it? I guess it has to do with how the Movie object is used, but I haven't seen examples in the documentation on why/how to safely exit.</p>
]]></description>
   </item>
   <item>
      <title>How align textures using GLSL for depth and RGB of kinect</title>
      <link>https://forum.processing.org/two/discussion/25414/how-align-textures-using-glsl-for-depth-and-rgb-of-kinect</link>
      <pubDate>Wed, 06 Dec 2017 10:56:45 +0000</pubDate>
      <dc:creator>Aurelian24</dc:creator>
      <guid isPermaLink="false">25414@/two/discussions</guid>
      <description><![CDATA[<p>Im working on a proyect that needs to cut the background and and show only the figure with RGB colors for this im using a kinect and use a video as background. This has to work on the raspberry PI. The only kinect library that works on the raspberry is open Kinect. Open kinect doesn´t have the mask function nor the skeleton function.</p>

<p>I´ve accoplish to create a mask that works pretty well on the raspberry using shaders thought the problem that im having is that the RGB and Depth textures are not aligned. I´ve heard that this is something that happends with the kinect 1414 and not with the kinect 1417, thought i´ve only got the 1414 model , so i have to make it work in here.</p>

<p>This is a reference pic of how the mask is working:<img src="" alt="" /></p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/707/5NGLZMR3GII1.png" alt="mascara" title="mascara" /></p>

<p>The thing in the background is the video, look how wrong the mask is.</p>

<p>Im testing it on windows, so im using kinect4win library, and i know kinect4win has the kinect.getMask() function that works perfectly but i need to run on the raspberry so that function is useless and so i have to make my own. Here is my code using kinect4win than then im going to translated openKinect :</p>

<p>PROCESSING :</p>

<pre><code>import processing.video.*;
import kinect4WinSDK.Kinect;

import processing.video.*;

Movie movie;

Kinect kinect;


PGraphics canvas;
PShader shader;

// brightness threshold
float minBrightness = 0.8;


//Values tested on  kinect4windows
float scale = 0.9099997;
float xoffset = 0.08226191;
float yoffset = 0.08226191;

//values tested on openKinect for raspberry pi
/*float scale = 1.0799996;
float xoffset = -0.007174231;
float yoffset = -0.07838542;*/

void setup()
{
  fullScreen(P2D);
  //size(640, 480, P2D);
  frameRate(60);

  kinect = new Kinect(this);
  // load shader and set threshold
  shader = loadShader("mask.glsl");

  // Load and play the video in a loop
 /* movie = new Movie(this, "transit.mov");
  movie.loop();*/

  shader.set("xoffset", xoffset);
  shader.set("yoffset", yoffset);
  shader.set("scale", scale);
}

void draw()
{
  // reset screen
  background(0, 0);
  // visualise result
  shader.set("umbral", minBrightness);

  //0.05 PUEDE IR EH
  float xoffset = map(mouseX, 0, width, -0.1, 0.1);
  float yoffset = map(mouseY, 0, height, -0.1, 0.1);



  println("X Offset : ", xoffset);
  println("Y Offset : ", yoffset);


  fill(255, 0, 0);
  ellipse(mouseX, mouseY, 20, 20);

  /*fill(0);
  image(movie, 0, 0, width, height);
  fill(255);
  */

  shader.set("texture", kinect.GetDepth());
  shader.set("texture2", kinect.GetImage());

  shader(shader);
  image(kinect.GetDepth(), 0, 0, width, height);
  resetShader();

  fill(0, 255, 0);

  float sep = 20;
  text("FPS: " + frameRate, 10, height-sep);
  text("xoffset :" + xoffset, 10, height-sep*2);
  text("yoffset :" + xoffset, 10, height-sep*3);
  text("scale :" + scale, 10, height-sep*4);
}

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

void keyPressed() {

  if (key == '+') {

    minBrightness +=0.1;
  }
  if (key == '-') {

    minBrightness -=0.1;
  }

  if(key == 'a'){

   scale +=0.02; 
  }
  if(key == 's'){
   scale -= 0.02; 
  }
}
</code></pre>

<p>This is my GLSL CODE :</p>

<pre><code>     /*#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
*/
uniform sampler2D texture; //LA DEPTH

uniform sampler2D texture2; // LA RGB

varying vec4 vertColor;
varying vec4 vertTexCoord;

uniform float umbral;
uniform float xoffset;
uniform float yoffset;
uniform float scale;

void main() {
    vec3 luminanceVector = vec3(0.2125, 0.7154, 0.0721);
    vec4 c = texture2D(texture, vertTexCoord.st) * vertColor;


    //CORRECT DEPTH RGB ALIGMENT : 

    vec4 c2 =  texture2D(texture2, (vertTexCoord.st+vec2(xoffset,yoffset))*scale) * vertColor;

    float luminance = dot(luminanceVector, c.xyz);
    luminance = max(0.0, luminance - umbral);


    c.r = c2.r;
    c.g = c2.g;
    c.b = c2.b;
    c.a = sign(luminance);

    gl_FragColor = vec4(c.rgb,c.a);
}
</code></pre>

<p>Im posting this on shaders category cause all that i need to do is translate the depth mask to be align to the RGB, but im not very good using shaders. so my question is . How to translate depth mask to align to rgb texture?</p>

<p>UPDATE : i´ve managed to set a Xoffset and Yoffset for aligning the textures, yet it doesn´t seem to be only a problem of aligment but also a problem of scale, like the depth image is a bit larger. Maybe some OpenCV algorithm for improving it?</p>

<p>UPDATE2: i´ve managed to set a SCALE, better, but still inacurate, i don´t know how to solve this now.</p>

<p>UPDATE3: SOLVE IT ! the scale was not really add it, now the code is fully functional</p>
]]></description>
   </item>
   <item>
      <title>Why does video start playing before it is called in a pathway?</title>
      <link>https://forum.processing.org/two/discussion/25313/why-does-video-start-playing-before-it-is-called-in-a-pathway</link>
      <pubDate>Fri, 01 Dec 2017 01:38:08 +0000</pubDate>
      <dc:creator>mnoble</dc:creator>
      <guid isPermaLink="false">25313@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I am trying to get the video to not begin playing until stage 1, but it starts right away. Any suggestions? Thank you!</p>

<pre><code>PImage old;
import processing.video.*;
Movie movie;
int stage = 0;


void setup(){
size(500,500);
old = loadImage("old.png");
old.resize(500,500);
  movie = new Movie(this, "full.mov");
  movie.loop();
}

void draw(){
if (stage == 0){
  fill (255,0,0);
  rect (0,0,500,500);
  if ((mousePressed)&amp;&amp; (mouseX &gt; 0) &amp;&amp; (mouseX &lt; 250)&amp;&amp; (mouseY &gt; 0) &amp;&amp; (mouseY &lt; 250)){ //button on upper left side
    stage = 1;
  }
}

if (stage == 1){ 
 image(movie,0,0,500,500);
 image(old,0,0,500,500); 

}

}

void movieEvent(Movie m){
  m.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>blend() and filter() significantly slow down 1080p Video FPS to 7; Any solutions?</title>
      <link>https://forum.processing.org/two/discussion/23072/blend-and-filter-significantly-slow-down-1080p-video-fps-to-7-any-solutions</link>
      <pubDate>Thu, 15 Jun 2017 06:03:24 +0000</pubDate>
      <dc:creator>SpPank</dc:creator>
      <guid isPermaLink="false">23072@/two/discussions</guid>
      <description><![CDATA[<p>//hey, I'm probably not doing this right
//is it cause I'm using the context of PGraphics and PImage mixed up??
//IM GETTING 7 FPS W/ I7 7700K AND 1070 sli
//CPU AND GPU ARE NOT BEING PUSHED
///NEED HELP!!!!</p>

<p>import java.util.ArrayList;
import KinectPV2.KJoint;
import KinectPV2.*;</p>

<p>KinectPV2 kinect;</p>

<p>import processing.video.*;</p>

<p>Movie coral;
PGraphics feedback;</p>

<p>void setup() {
  fullScreen(P2D, 2);
  feedback = createGraphics(1920,1080,P2D);
  background(0);
  //blendMode(ADD);</p>

<p>//Video stuff
  coral = new Movie(this, "CoralReef.mp4");
  coral.loop();</p>

<p>//Kinect stuff
  kinect = new KinectPV2(this);
  kinect.enableBodyTrackImg(true);
  kinect.enableSkeletonDepthMap(true);
  kinect.init();
}</p>

<p>void movieEvent(Movie m) {
  m.read();
}</p>

<p>PImage kinectSil;</p>

<p>void draw() {</p>

<p>kinectSil = kinect.getBodyTrackImage();</p>

<p>kinectSil.filter(INVERT);
  kinectSil.loadPixels();
  for (int i = 0; i &lt; kinectSil.pixels.length; i++) {
    if (kinectSil.pixels[i] == color(0)) {
      kinectSil.pixels[i] = color(0, 0);
    } else {
      kinectSil.pixels[i] = color(255,255);
    }
  }
  kinectSil.updatePixels();</p>

<p>feedback.beginDraw();
  feedback.image(kinectSil,0,0,1920,1080);
  feedback.blend(coral, 0, 0, coral.width, coral.height, 0, 0, coral.width, coral.height, MULTIPLY);
  feedback.filter(THRESHOLD);
  feedback.endDraw();
  tint(255,10);
  image(coral,0,0,width,height);
  blend(feedback,0,0,feedback.width,feedback.height, 0, 0, width, height, LIGHTEST);
  fill(45);
  rect(0,0,150,54);
  textSize(30);
  fill(255);
  text(frameRate, 20,40);
}</p>
]]></description>
   </item>
   <item>
      <title>Set distance value with ultrasonic sensor</title>
      <link>https://forum.processing.org/two/discussion/25094/set-distance-value-with-ultrasonic-sensor</link>
      <pubDate>Sun, 19 Nov 2017 18:11:54 +0000</pubDate>
      <dc:creator>ilayes</dc:creator>
      <guid isPermaLink="false">25094@/two/discussions</guid>
      <description><![CDATA[<p>I want to set the distance from the ultrasonic sensor. For instance, I want to play a video between 0 and 100 cm. 
Also I stop this video 100 between 250. But I did not write this code part. Can you help me pls ??  :( 
(I wrote arduino code but I stuck in processing part )</p>
]]></description>
   </item>
   <item>
      <title>Series of Videos triggered by time based clicks</title>
      <link>https://forum.processing.org/two/discussion/24992/series-of-videos-triggered-by-time-based-clicks</link>
      <pubDate>Mon, 13 Nov 2017 22:03:17 +0000</pubDate>
      <dc:creator>msilva2018</dc:creator>
      <guid isPermaLink="false">24992@/two/discussions</guid>
      <description><![CDATA[<p>Im trying to have a code where the user clicks and the video plays; then after the video is done, the user clicks again and so on and so on. My problem is how do I do this? I have the videos but they play on top of each other and the first video never goes away. 
Heres the code</p>

<p>PImage img1;</p>

<p>//movie var, name after actual movie!
Movie wtch1;
Movie wtch2;
Movie wtch3;
Movie wtch4;
Movie wtch5;</p>

<p>//The var to control what movie plays next(hopefull)---------------------------------Movie var
float mvar = 1;</p>

<p>void setup () {
  size (1152, 864);</p>

<p>//starting image
  img1 = loadImage("Send.png");</p>

<p>//video stuff-----------------------------------------------------------------setup video
  wtch1 = new Movie(this, "wtch1.mov");
  wtch2 = new Movie(this, "wtch2.mov");
  wtch3 = new Movie(this, "wtch3.mov");
  wtch4 = new Movie(this, "wtch4.mov");
  wtch5 = new Movie(this, "wtch5.mov");
  //</p>

<p>//
}</p>

<p>void draw () {
  background(0);
  //-----------------------------------------------------------------------Starting image
  tint(255, 255);
  image(img1, 0, 0, width, height);</p>

<p>image(wtch1, 0, 0, width, height);//////-------------------------------------wtch1 AND if AND mvar
  if(mousePressed){
    wtch1.play();</p>

<p>if(mousePressed &amp;&amp; mvar == 2){
    image(wtch2, 0, 0, width, height);
    wtch2.play();
    mvar = 3;
  }</p>

<p>}</p>

<p>void movieEvent (Movie m) { //---------------------------------------------------Movie m| m.read
  m.read();
}</p>
]]></description>
   </item>
   <item>
      <title>Processing+OpenCV - FaceDetection on a Movie</title>
      <link>https://forum.processing.org/two/discussion/24824/processing-opencv-facedetection-on-a-movie</link>
      <pubDate>Tue, 31 Oct 2017 20:41:47 +0000</pubDate>
      <dc:creator>Jawah</dc:creator>
      <guid isPermaLink="false">24824@/two/discussions</guid>
      <description><![CDATA[<p>I am using Processing with the OpenCV Lib and wanted to rewrite the example Code from the creators Git so that instead of doing Face Detection on a Camera Capture I'll load a video (.mp4).</p>

<p>Link to the Git and the example Code (which is working): <a rel="nofollow" href="https://github.com/atduskgreg/opencv-processing/blob/master/examples/LiveCamTest/LiveCamTest.pde">Link</a></p>

<p>Here is my Sketch:</p>

<pre><code>import processing.video.*;
import gab.opencv.*;
import java.awt.Rectangle;

OpenCV opencv;
Movie myMovie;
Rectangle[] faces;

void setup() {
  size(480, 270);

  myMovie = new Movie(this, "people3.mp4");
  myMovie.loop();
  opencv = new OpenCV(this, myMovie.width, myMovie.height);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
}

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

void draw() {

  background(0);
  if (myMovie.available()) {    

    opencv.loadImage(myMovie);
    faces = opencv.detect();
    image(myMovie, 0, 0);

    if (faces != null) {
      for (int i = 0; i &lt; faces.length; i++) {
        strokeWeight(2);
        stroke(255, 0, 0);
        noFill();
        rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
      }
    }
  }
}
</code></pre>

<p>What I'm getting is an
<strong>IndexOutOfBoundsException: Index: 3, Size: 0</strong>
at openCV.loadImage(myMovie) and I don't know why.</p>

<p>Appreciating any help! :-)</p>
]]></description>
   </item>
   <item>
      <title>Port get busy after a few times running. Is it because of P3D?</title>
      <link>https://forum.processing.org/two/discussion/24569/port-get-busy-after-a-few-times-running-is-it-because-of-p3d</link>
      <pubDate>Sun, 15 Oct 2017 23:56:57 +0000</pubDate>
      <dc:creator>TuangPing</dc:creator>
      <guid isPermaLink="false">24569@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have come to a problem of having error from using Window 7 with arduino Leonado sending data through Serial port.
I tested a code that getting only the data from both Mac and Window and it works fine. Then I make a video to put on a canvas for Spout to project it out to other program. Note that with syphon everything works fine too. I have ran into a post somewhere that posted long ago that a guy had the same problem of mine and he fixed it by changing to openGL but I also learned that openGL now is the same as P3D from a more recent post here in this forum. ** I didn't run anything at the same time of processing.** First time running usually fine, but for the second or third then the error will say that my port is busy! And I will have no choice but  restart the computer again. !!!! Is this a bug? Is there a solution?</p>

<p>Here is the code that runs fine on both operation</p>

<pre><code>import processing.serial.*;
Serial myPort ;
int value, wheel;
String myString = null;
int weight = 800;
int lf = 10;

void setup() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.clear();
  myPort.bufferUntil(lf);
  myString = myPort.readStringUntil(lf);
}
void draw() {
println("in draw once");
 println("fsr: "+ value);
    println("wheel position: "+ wheel);
    println("-----------");
}

void serialEvent(Serial p) {
  //println("access Serial port");
  myString = p.readStringUntil('\n');
  if (myString !=null) {
    //println("get data from Serial port");
    String[] fsr =split(myString, 'r');
    //printArray(fsr);
    value = int(fsr[0]);
    String trim = trim(fsr[1]);
    wheel = int(trim);

  }
}
</code></pre>

<p>And this is a code that has a problem in Window 7 (x64)</p>

<pre><code>import spout.*;// IMPORT THE SPOUT LIBRARY
import processing.serial.*;//Serial to Arduino
import processing.video.*;//play vdo

int nSenders = 5;
PGraphics[] canvas;
Spout[] senders;

int lf=10;
Serial myPort;
int value, wheel;
String myString = null;
Movie myMovie;
int arduinoValue = 800;

int projectorWidth = 1024;
int projectorHeight = 768;
//int scalar = 3;

//-----swtiches------//
Boolean arduinoSwitch = true;
Boolean sensorSwitch = false;
Boolean spoutSwitch = true;
//-----------//

void settings() {
  size(projectorWidth, projectorHeight,P3D);
  // size is doesn't change the size of canvas in term of sending graphic signal out.
}
void setup() {
  canvas = new PGraphics[nSenders];
  for (int i=0; i&lt;nSenders; i++) {
    canvas[i] = createGraphics(projectorWidth, projectorHeight, P3D);
  }
  printArray(Serial.list());

  // Create Spout senders to send frames out.
  if (spoutSwitch) {
    senders = new Spout[nSenders];
    for (int i = 0; i &lt; nSenders; i++) { 
      senders[i] = new Spout(this);
      String sendername = "Test "+i;
      senders[i].createSender(sendername, projectorWidth, projectorHeight);
    }
  }  
  if (arduinoSwitch) {
    myPort = new Serial(this, Serial.list()[1], 9600);
    myPort.clear();
    myPort.bufferUntil(lf);
    myString = myPort.readStringUntil(lf);
  }
  myMovie = new Movie (this, "C:/Users/dma/Desktop/tuang/test1.mp4");
}

void draw() {
  canvas[0].beginDraw();
  canvas[0].background(255, 0, 100);
  canvas[0].image(myMovie, 0, 0);
  if (spoutSwitch) {
    for (int i = 0; i &lt; nSenders; i++) {
      senders[i].sendTexture(canvas[i]);    //send all separated spout canvases
    }
  }
  if (arduinoSwitch) {
    println("fsr: "+value);
    println("position wheel: "+wheel);
    if (value &lt; arduinoValue) {
      sensorSwitch=true;
      myMovie.stop();
      canvas[0].background(0);
      println("nothing in the house");
    }
    if (sensorSwitch) {
      if (value&gt;=arduinoValue) {
        println("Force sensor is detacted");
        //newRandom=true;
        //randomMovie();
        myMovie.play();
        sensorSwitch=false;
      }
    }
  }
  canvas[0].endDraw();
  image(canvas[0], 1024/2*(0%2), 768/2*(0/2));
}
void movieEvent(Movie m) {
  m.read();
}

void serialEvent(Serial p) {
  if (arduinoSwitch) {
    myString = p.readStringUntil('\n');
    if (myString != null) {
      String[] fsr = split(myString, 'r');
      //printArray(fsr);
      value = int(fsr[0]);
      String trim = trim(fsr[1]);
      wheel = int(trim);
    }
  } else {
    println("Arduino is off.");
  }
}
//keyboard for testing vdo
void keyPressed() {
  switch (key) {
  case 'a' : 
    myMovie.play();
    break;
  case 'r' :
    myMovie.stop();
    break;
  }
}
</code></pre>

<p>What should I do to stop the port being too busy ! I didn't even run anything but processing.</p>
]]></description>
   </item>
   <item>
      <title>when i play nine mp4s using video library,the nineth mp4 can't play as other eight mp4.</title>
      <link>https://forum.processing.org/two/discussion/24050/when-i-play-nine-mp4s-using-video-library-the-nineth-mp4-can-t-play-as-other-eight-mp4</link>
      <pubDate>Thu, 07 Sep 2017 05:23:47 +0000</pubDate>
      <dc:creator>Ryan</dc:creator>
      <guid isPermaLink="false">24050@/two/discussions</guid>
      <description><![CDATA[<pre><code>import processing.video.*;  
import processing.serial.*; 
Serial myPort;
int[] valr={1021,1021,1021,1021,1021,1021,1021,1021,1021};
Movie[] endmovie = new Movie[9];
void setup(){  
  fullScreen();
  for(int i = 0;i&lt;9;i++){
endmovie[i] = new Movie(this,"b"+i+".mp4");
  }
  myPort = new Serial(this,Serial.list()[0], 9600);
  myPort.bufferUntil('\n');  //buffer until meet '\n', then call the event listener

}  

void draw(){
  image(endmovie[0],0,0,width/3,height/3);
  image(endmovie[1],width/3,0,width/3,height/3);
  image(endmovie[2],width*2/3,0,width/3,height/3);
  image(endmovie[3],0,height/3,width/3,height/3);
  image(endmovie[4],width/3,height/3,width/3,height/3);
  image(endmovie[5],width*2/3,height/3,width/3,height/3);
  image(endmovie[6],0,height*2/3,width/3,height/3);
  image(endmovie[7],width/3,height*2/3,width/3,height/3);
  image(endmovie[8],width*2/3,height*2/3,width/3,height/3);
for(int i = 0;i&lt;9;i++){
  endmovie[i].play();
   if(valr[i]&gt;500){
endmovie[i].speed(1.0);
   }else{
endmovie[i].speed(-1.0);
   }
 }
}

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

void serialEvent(Serial p) {  
  String inString = p.readString();  
  print(inString);
  if(inString!=null){
   String[] rec= split(inString, ',');
   for(int i=0;i&lt;9;i++){
 valr[i]=int(rec[i]);
   }  
  }  
}  
</code></pre>
]]></description>
   </item>
   <item>
      <title>I need to saveFrame() while showing a video on the sketch display screen</title>
      <link>https://forum.processing.org/two/discussion/23435/i-need-to-saveframe-while-showing-a-video-on-the-sketch-display-screen</link>
      <pubDate>Thu, 13 Jul 2017 16:26:18 +0000</pubDate>
      <dc:creator>m4rdones</dc:creator>
      <guid isPermaLink="false">23435@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I have a new question about code. 
I'm trying to save frames from a web cam while a video is playing in the screen.</p>

<p>I have this code that allows me to save frames, but I don't want to save frames from the displayed video. What I'm not seeing?</p>

<p>Thanks in advance!</p>

<pre><code>import processing.video.*;

Capture cam;
Movie video;

boolean showVideo=false;
boolean saveframe=false; 

void setup() { 
  size(640, 480); 
  cam = new Capture(this, 640, 480, 30);
  video = new Movie(this, "ex.mp4");
  cam.start();
} 


void draw() {
  background(0);
  if (showVideo==false) { 
    image(cam, 0, 0);
  } else {
    image(video, 0, 0);   
  }
  if (saveframe==true) {saveFrame("output.##.jpg");
  }
}

void keyPressed() {
  showVideo=true;
  video.loop();
  saveframe=true;
}

void keyReleased() {
  showVideo=false;
  video.stop();
  saveframe=false;
}

void captureEvent(Capture webCam) {
  webCam.read();
}

void movieEvent(Movie m) {
  m.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Issue with video player</title>
      <link>https://forum.processing.org/two/discussion/22991/issue-with-video-player</link>
      <pubDate>Thu, 08 Jun 2017 21:47:06 +0000</pubDate>
      <dc:creator>lolonulu</dc:creator>
      <guid isPermaLink="false">22991@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I wrote this class dedicated to a video player. I want to read videos when I click on 3d spheres in my main tab. How should I proceed to choose my videos inside the videoList, (they have the same names than the spheres) with an index ?
I click on a sphere, it plays the full screen video wich has the same name than the sphere, then the video stop, window closes and go back to interface with the spheres and so on... Do someone know how I should start? Thanks a lot in advance for your help ;)</p>

<pre><code>class Movie {


  int currentMovieIndex;
  int STATE_PLAYING_SELECTED_MOVIE;
  int currentState = STATE_PLAYING_SELECTED_MOVIE, STATE_WAITING_FOR_CLICK;
  float movieEndDuration = 0.039719;
  String [] stateLabels = {"waiting for click", "playing selected movie"};

  String [] videoList= {"obscurité", "sombre"};
  Movie[] movies;

  Movie(movies, String[]videoList) {

    Movie[] movies = new Movie[videoList.length]; 
    for (int i=0; i &lt; videoList.length; i++) {
      movies[i] = new Movie(this, videoList[i]+".mp4");
      movies[currentMovieIndex].play();
    }
  }


  void drawMovie() {
    background(0);
    image(movies[currentMovieIndex], 0, 0);
  }
  void playSelectedMovie() {
    currentState = STATE_PLAYING_SELECTED_MOVIE;
    movies[currentMovieIndex].play();
  }

  void movieEvent (Movie m) {

    if (currentState == STATE_PLAYING_SELECTED_MOVIE) {
      if ((m.time()+ movieEndDuration) &lt; m.duration) {
        m.read();
        movies[currentMovieIndex].play();
      } else if ((m.time() +movieEndDuration)&gt;= m.duration()) { 
        m.stop();
        currentState = STATE_WAITING_FOR_CLICK;
        println("movie at index " + currentMovieIndex + " finished playback, current state: " + stateLabels[currentState]);
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Random video</title>
      <link>https://forum.processing.org/two/discussion/23453/random-video</link>
      <pubDate>Sat, 15 Jul 2017 14:46:45 +0000</pubDate>
      <dc:creator>twip</dc:creator>
      <guid isPermaLink="false">23453@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, a newbie question here. I´m trying to select video files that will play in a random sequence. Every time I replay the sketch I see a new video, but does anyone know how to get them to play in sequence without refreshing the sketch? I´m probably missing something obvious here, grateful for any help!</p>

<pre><code>import processing.video.*;

String[]vid = {"action1.mp4", "action2.mp4", "action3.mp4", "action4.mp4", "action5.mp4", "action6.mp4"};

Movie movie;

void setup() {
  size(480, 270);
  background (255);
  frameRate(30);
  movie = new Movie(this, vid[int(random(1, 6))]);
  movie.loop();
}

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

void draw() {
  image(movie, 0, 0 );
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Resizing a Movie - Possible Bug?</title>
      <link>https://forum.processing.org/two/discussion/23389/resizing-a-movie-possible-bug</link>
      <pubDate>Mon, 10 Jul 2017 14:14:46 +0000</pubDate>
      <dc:creator>danlj</dc:creator>
      <guid isPermaLink="false">23389@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm getting some inconsistent behaviour with PImage.width, PImage.height, and PImage.resize() when working with Movie files. Width and height will almost always return 0, though will occasionally return the correct dimensions. PImage.resize() will sometimes throw an error: "Width(0) and Height(0) cannot be &lt;= 0" - even when the dimensions are hardcoded in. I'm posting this here because I'm not sure whether this is a bug or I'm just doing something silly with the code:</p>

<p>macOS 10.12.5; Quicktime 10.4; P3.3.5</p>

<pre><code>import processing.video.*;

Movie m;
PImage mS;
int vScale = 4;
int mW;
int mH;

void setup() {
  size(480, 270);
  m = new Movie(this, "test.mov"); // original dim: 1920 1080
  m.loop();
  mW = m.width; 
  mH = m.height;

  // Almost always returns 0 for both values, but occasionally returns the correct dimensions.  
  println("width: " + mW +" " + "Height: " + mH); 
}

void draw() {
  mS = m.get();

  //This almost never works
  //mS.resize(mW/vScale, mH/vScale); 

  //This works most of the time, but not always!
  //mS.resize(1920/vScale, 1080/vScale); 

  //Again works most of the time, but not always...
  mS.resize(480, 270);


  image(mS, 0, 0);
}

void movieEvent(Movie m) {
 m.read(); 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make keyPressed respond to the number of times the key is pressed</title>
      <link>https://forum.processing.org/two/discussion/16476/how-to-make-keypressed-respond-to-the-number-of-times-the-key-is-pressed</link>
      <pubDate>Sat, 07 May 2016 14:09:13 +0000</pubDate>
      <dc:creator>kk324</dc:creator>
      <guid isPermaLink="false">16476@/two/discussions</guid>
      <description><![CDATA[<p>I'm very new to Processing. I am working on a project that involves Makey Makey. 
I was wondering if it is possible to use keyPressed or something similar to respond to the number of times the key is pressed?
For instance, I want the user to press LEFT three times and RIGHT two times, and after that the video will play. Is there a way to do it?</p>
]]></description>
   </item>
   <item>
      <title>LINUX Combining Video and Audio - Video won't play anymore</title>
      <link>https://forum.processing.org/two/discussion/23167/linux-combining-video-and-audio-video-won-t-play-anymore</link>
      <pubDate>Thu, 22 Jun 2017 13:51:06 +0000</pubDate>
      <dc:creator>kmvtxx</dc:creator>
      <guid isPermaLink="false">23167@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>I have been working with video and audio during a project, and when they both seemed to work properly I decided to put them together.
After searching for the problem in my code, I found that loading in the audio files blocked the ability to play a video.
I isolated the part of the code that does not work:</p>

<pre><code>import processing.video.*;
import processing.sound.*;

SoundFile ring;

Movie mov1;


void setup() {

  size(200,200);
  background(0);

  mov1 = new Movie(this, "VIDEO1.mp4");
  ring = new SoundFile (this, "vintage.mp3");  //soundfile phone ringing
  mov1.loop();                                         
}

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

void draw() {
  image(mov1, 0, 0, width, height);
}
</code></pre>

<p>When I remove the part "ring = new SoundFile (this, "vintage.mp3")" it the video plays, but otherwise it won't.</p>

<p>I have no clue how to solve this problem, do you?</p>

<p>Thank you in advance! :)</p>
]]></description>
   </item>
   <item>
      <title>Creating an array with movie files, and shuffling it.</title>
      <link>https://forum.processing.org/two/discussion/23023/creating-an-array-with-movie-files-and-shuffling-it</link>
      <pubDate>Sun, 11 Jun 2017 13:05:54 +0000</pubDate>
      <dc:creator>blazebattery</dc:creator>
      <guid isPermaLink="false">23023@/two/discussions</guid>
      <description><![CDATA[<p>Hey everyone,</p>

<p>I'm creating a movie player program with an Arduino board. I've successfully made the program play one movie file when I wave my hand in front of the Arduino PIR monitor, I just want it to randomly select from an array of other video files. Any help would be appreciated.</p>

<p>Here's my code so far...</p>

<pre><code>import processing.video.*;
import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph, original 1
float inByte = 0;

String[] movieNames = { "1.mpg", "2.mpg", "3.mpg", "4.mpg"};
Movie[] movee = new Movie[movieNames.length];

void setup() {
  fullScreen();
  background(0);

  myPort = new Serial (this, "COM6", 9600);
  myPort.bufferUntil('\n');

  for (int i=0; i&lt;movieNames.length; i++) {
    movee[i] = new Movie(this, movieNames[i]);
  }
}

void draw() {

  for (int i = 0; i &lt; movieNames.length; i++) {
    image(movee[0], 0, 0);
  }
}

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

void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    inString = trim(inString);
    inByte = float(inString);

    println(inByte);

    if (inByte == 1) {
      movee[0].stop();
      println("Playing video...");
      movee[0].play();
    }

  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can anyone help me find what's wrong with my code for a video player based off sensor reading</title>
      <link>https://forum.processing.org/two/discussion/22640/can-anyone-help-me-find-what-s-wrong-with-my-code-for-a-video-player-based-off-sensor-reading</link>
      <pubDate>Wed, 17 May 2017 16:53:23 +0000</pubDate>
      <dc:creator>Tom_Partington</dc:creator>
      <guid isPermaLink="false">22640@/two/discussions</guid>
      <description><![CDATA[<p>I'm fairly new to processing and it's my first time involving videos. I am currently using Arduino and Processing to create touch sensitive video player. I have managed to get Arduino to send the readings to Processing and it is reading them. But I can't get the videos to play properly when a sensor is activated (going from 0&gt;1). I think there might be a few things wrong/missing with the code or certain things in the wrong place. A blank screen currently loads when I run the sketch and doesn't change even when activating the sensors.
I have the video files in a 'data' folder within the sketch folder so I think they are in the right place. Any help at all is greatly appreciated. Code below;</p>

<pre><code>import processing.serial.*;
import processing.video.*;

Movie movie1;
Movie movie2;
Movie movie3;
//etc.

Serial myPort;
int linefeed = 10;   // Linefeed in ASCII
int numSensors = 3;  // we will be expecting for reading data from four sensors (CHANGE)
int sensors[];       // array to read the values
int pSensors[];      // array to store the previuos reading, useful for comparing
// actual reading with the last one

String currentMovie;

void setup() {
  size(1440, 1080);

  println(Serial.list());

  // files inside processing folder for this programme
  movie1 = new Movie(this, "Sun.mp4");
  movie2 = new Movie(this, "Mercury.mp4");
  movie3 = new Movie(this, "Venus.mp4");
  //etc.

  myPort = new Serial(this, Serial.list()[3], 115200);
  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil(linefeed);
}

void draw() {

  // check the sensors and sets the movie to play

  if (currentMovie == "")        //if nothing is playing
  {
    if (sensors[0] == 1)
    {
      //print("Play Movie 1");
      currentMovie = "movie1";
      movie1.play();
    } else if (sensors[1] == 1)
    {
      print("Play Movie 2");
      currentMovie = "movie2";
      movie2.play();
    } else if (sensors[2] == 1)
    {
      print("Play Movie 3");
      currentMovie = "movie3";
      movie3.play();
    }
  } else
  {
    // do nothing (if a movie is playing do nothing)
  }

  // show the movie frames

  if (currentMovie == "movie1")
  {
    if (movie1.available())
    {
      image(movie1, 0, 0);
    } else
    {
      currentMovie = "";    // if a frame is available, show the next frame. This means once the video ends it will play nothing.
    }
  } else if (currentMovie == "movie2")
  {
    if (movie2.available())
    {
      image(movie2, 0, 0);
    } else
    {
      currentMovie = "";
    }
  } else if (currentMovie == "movie3")
  {
    if (movie3.available())
    {
      image(movie3, 0, 0);
    } else
    {
      currentMovie = "";
    }
  }
}

void serialEvent(Serial myPort) {

  // read the serial buffer:
  String myString = myPort.readStringUntil(linefeed);

  // if you got any bytes other than the linefeed:
  if (myString != null) {

    myString = trim(myString);

    // split the string at the commas
    // and convert the sections into integers:

    pSensors = sensors;
    sensors = int(split(myString, ','));

    // print out the values you got:

    for (int sensorNum = 0; sensorNum &lt; sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    }

    // add a linefeed after all the sensor values are printed:
    println();
  }
}

void movieEvent(Movie m) {
  m.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to remove alpha transparency from video ?</title>
      <link>https://forum.processing.org/two/discussion/22405/how-to-remove-alpha-transparency-from-video</link>
      <pubDate>Fri, 05 May 2017 11:55:12 +0000</pubDate>
      <dc:creator>saurabh</dc:creator>
      <guid isPermaLink="false">22405@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>how can i play alpha transparent video without P3D OR P2D render ?</p>

<p>any help will be good</p>

<p>Thanks.</p>

<p>mycode:</p>

<pre lang="java">
import processing.video.*;
Movie mov;
PImage img;

Capture cam;

void setup() {
  size(640, 480);
  frameRate(30);

  mov = new Movie(this, "../../../files/movie/Final.mov");
  mov.play();

  cam = new Capture(this, 640, 480);
  cam.start();
}

void draw() {

  background(0);
  image(cam, 0, 0);
  image(mov, 0, 0);

}

void movieEvent(Movie m) {
  m.read();
}
void captureEvent(Capture cam) {
  cam.read();
}
</pre>
]]></description>
   </item>
   <item>
      <title>Processing not reacting properly to arduino via firmata</title>
      <link>https://forum.processing.org/two/discussion/22376/processing-not-reacting-properly-to-arduino-via-firmata</link>
      <pubDate>Thu, 04 May 2017 00:01:46 +0000</pubDate>
      <dc:creator>ailisg</dc:creator>
      <guid isPermaLink="false">22376@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I'm using an arduino uploaded with firmata. I have a potentiometer hooked up and as the user turns the potentiometer, depending on the value they land on, a certain video will play. So if they turn it up more a different video will play etc.
What's happening is I have to turn the potentiometer to a value, and then turn it all the way back to zero and then the corresponding video from the first value will play. In between it's showing the "image" I'm calling as a part of the video, but usually only one of them, not all of them. I'm new to the video library and processing &amp; arduino in general.
Thanks for your help!</p>

<pre><code>import processing.serial.*;

import cc.arduino.*;
import org.firmata.*;


import processing.video.*;

Arduino arduino;

Movie oneDegree, twoDegrees, threeDegrees;


int sensorPin = 0;    // select the input pin for the potentiometer
int val;



void setup() {
  size(960, 540);
  arduino = new Arduino(this, Arduino.list()[3], 57600); //sets up arduino
   val = arduino.analogRead(sensorPin); 
   println(Arduino.list());
   oneDegree = new Movie(this, "comp1.mp4");
   twoDegrees = new Movie(this, "comp2.mp4");
   threeDegrees = new Movie(this, "comp3.mp4");


}

void draw() {
 val = arduino.analogRead(sensorPin); 
 println(val);
 image(oneDegree, 0, 0);
 image(twoDegrees, 0, 0);
 image(threeDegrees, 0, 0);

  if(val &gt; 10 &amp;&amp; val &lt; 348) { 
    oneDegree = new Movie(this, "comp1.mp4");
    oneDegree.play();
  }

  else if(val &gt; 348 &amp;&amp; val &lt; 686) {
  twoDegrees = new Movie(this, "comp2.mp4");
    twoDegrees.play();
  }

  else if(val &gt; 686 &amp;&amp; val &lt; 1024) {
   threeDegrees = new Movie(this, "comp3.mp4");
  threeDegrees.play();
  }

  if (oneDegree.time() == oneDegree.duration()) { //movie must be finished
twoDegrees.play();
  }
if (twoDegrees.time() == twoDegrees.duration()) { //movie must be finished
threeDegrees.play();
}
}

void movieEvent(Movie m) {
  m.read();
  /* if (m == oneDegree) {
    oneDegree.read();
  } 
  else if (m == twoDegrees) {
    twoDegrees.read();
  }
  else if (m == threeDegrees) {
    threeDegrees.read();
  }*/
}



/* void movieEvent(Movie ) {
  if (val &lt;= 348) {
    oneDegree.read();
  } 
  else if (val &gt; 348 &amp;&amp; val &lt;= 686) {
    twoDegrees.read();
  }

  else if (val &gt; 686 &amp;&amp; val &lt;= 1024) {
    threeDegrees.read();
  }
} */
</code></pre>
]]></description>
   </item>
   <item>
      <title>Trying to improve video performance</title>
      <link>https://forum.processing.org/two/discussion/22250/trying-to-improve-video-performance</link>
      <pubDate>Thu, 27 Apr 2017 17:17:22 +0000</pubDate>
      <dc:creator>laurabrooks</dc:creator>
      <guid isPermaLink="false">22250@/two/discussions</guid>
      <description><![CDATA[<p>I am creating an interactive 360 video sketch (with the help of <a rel="nofollow" href="https://github.com/muimota/p5video360">this shader</a> ) where a user will be able to speed and slow the clip (to make it look like they are moving through the scene) and look side to side by moving the mouse in the y and x directions, respectively. My goal is to display this sketch across three monitors so I would like to use high resolution video, however the sketch's performance worsens as the video quality increases and playback is often shaky. The shader seems to have very high performance but pausing and playing at different speeds sometimes makes the video jump or shake. I'm looking for solutions to make the video more smooth and be able to display it on a large area. I have allotted 1 gigabyte of memory to Processing through Preferences and I don't know if allotting more would solve my problem? Perhaps I just need a more powerful computer ( currently on 64-bit Windows, 4GB RAM)? I have looked into pre-loaded the whole video but haven't found anything promising.</p>

<p>Below is my code, any help is appreciated!</p>

<pre><code>import processing.video.*;

float joystick_yaw, joystick_speed;
Movie movie;
PShader shader;
float yaw, pitch, fov;
boolean isPaused = false;

void setup() {
  size(1280, 720, P2D);
  // pitch and yaw set to start video in desired view
  yaw   = 225;
  pitch = 5;
  fov   = 80;
  shader = loadShader("data/video360.glsl");
  shader.set("resolution", float(width/2), float(height/2));
  shader.set("yaw", yaw);
  shader.set("pitch", pitch);
  shader.set("fov", fov);
  movie = new Movie(this, "stitch_high.mp4");
  movie.play();
  movie.volume(0);
  while (movie.height == 0) {
    println("waiting " + second()); 
    delay(10);
  }

  imageMode(CORNERS);
}

void draw() {
  // display video  
  shader(shader);
  image(movie, 0, 0, width, height);

  // display yaw
  joystick_yaw = map(mouseX, 0, 1200, yaw-(fov/3), yaw+(fov/3)); 
  shader.set("yaw", joystick_yaw);

  //choose speed of video
  joystick_speed = map(mouseY, 0, height, 2, -2); 

  if (joystick_speed &gt; 0.2 &amp;&amp; isPaused ) {
    movie.speed(joystick_speed);
    movie.play();
    movie.speed(joystick_speed);
    isPaused = false;
  } else if (joystick_speed &lt; -0.2 &amp;&amp; isPaused) {
    movie.speed(joystick_speed);
    movie.play();
    movie.speed(joystick_speed);
    isPaused = false;
  } else if (joystick_speed &gt;= -0.2 &amp;&amp; joystick_speed &lt;= 0.2) {
    if (!isPaused) {
      movie.pause();
      isPaused = true;
    }
  }
}

// Called every time a new frame is available to read
void movieEvent(Movie m) {
  m.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to swap and play video files using functions</title>
      <link>https://forum.processing.org/two/discussion/22023/how-to-swap-and-play-video-files-using-functions</link>
      <pubDate>Sun, 16 Apr 2017 00:11:50 +0000</pubDate>
      <dc:creator>sheenakhu</dc:creator>
      <guid isPermaLink="false">22023@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys, I'm having some trouble getting this interactive piece to work. I want to hover over the top left of my sketch and have Scene 1 play. Then a minute later, hover over it and have Scene 2 play and around a minute and a half later, have Scene 3 play. However, the mouseX and mouse Y commands are ignored after Scene 1 plays through and when I input a timer, it is also ignored. In my final code, each scene function will contain 7 videos, so that's why I'm using "myMovie" as my base code and swapping different movie files in. For example, I will have myMovie1, myMovie2, myMovie3, myMovie4 etc, and load Scene 1's 7 files, dispose of them, then move onto scene 2's 7 files and eventually Scene 3's.</p>

<p>If anyone has any advice or can test this out it would be greatly appreciated. Thanks everyone!</p>

<pre><code>import processing.video.*; 

Movie myMovie;

boolean mouseInCorrectLocationToPlayVideo;

boolean hasMovieEnded;

float movieEndDuration = 0.1;

int whichSceneIAmCurrentlyOn = 0; 

void setup(){
size(640, 480);
frameRate(30);

loadScene1();

}    

void draw(){
println(millis());

    //Checking if movie has ended.
    //If movie has not yet ended, check mouseX &amp; Y location. 
    // If mouse is in these boundaries, mouseInCorrectLocationToPlayVideo is true.  
   if (hasMovieEnded == false){
      if ((mouseX &lt; 213) &amp;&amp; (mouseY &lt;= 240)){
        if((mouseX &gt; 0) &amp;&amp; (mouseY &gt;= 0)){

            mouseInCorrectLocationToPlayVideo = true;  
         }
       }
     }

    //If mouse X &amp; Y are not in these boundaries, print out.   
     if(mouseInCorrectLocationToPlayVideo == false){
     println("not in boundaries");
   }

   //If mouse X &amp; Y are in these boundaries, play video.
   if (mouseInCorrectLocationToPlayVideo == true) { 
    myMovie.play();
    image(myMovie, 0, 0);
    //println("1:" + frameCount);

    //When movie ends, dispose of movie file from memory. 
    if  ((myMovie.time() + movieEndDuration) &gt;= myMovie.duration()){

      myMovie.dispose();
      unregisterMethod("dispose", myMovie);
      g.removeCache(myMovie);
      println("current movie finished file dumped");

      //Movie has ended. 
      hasMovieEnded = true; 
      //MouseX and Y are not within stated boundaries anymore. 
      mouseInCorrectLocationToPlayVideo = false; 

      //  if (millis() &gt; 10*1000){ //not working
        if (whichSceneIAmCurrentlyOn == 1){
           reset();  
           loadScene2();
         }
      //   }
        else if (whichSceneIAmCurrentlyOn == 2){
          reset();   
          loadScene3();
        }  

    }          
  }  
} //closes draw

void reset(){
 // mouseInCorrectLocationToPlayVideo = false; //not needed
  hasMovieEnded = false;
}

void loadScene1(){

   myMovie = new Movie(this, "tileScene1.mp4");
   whichSceneIAmCurrentlyOn = whichSceneIAmCurrentlyOn + 1;
}

void loadScene2(){

    myMovie = new Movie(this, "tileScene2.mp4");
    whichSceneIAmCurrentlyOn = whichSceneIAmCurrentlyOn + 1;
}

void loadScene3(){

    myMovie = new Movie(this, "tileScene3.mp4");
    whichSceneIAmCurrentlyOn = whichSceneIAmCurrentlyOn + 1;
}


void movieEvent(Movie m) {
   if (m == myMovie) {
    myMovie.read();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Help needed getting Processing to open video files.</title>
      <link>https://forum.processing.org/two/discussion/21748/help-needed-getting-processing-to-open-video-files</link>
      <pubDate>Sat, 01 Apr 2017 17:27:37 +0000</pubDate>
      <dc:creator>harrisonh555</dc:creator>
      <guid isPermaLink="false">21748@/two/discussions</guid>
      <description><![CDATA[<p>hello,</p>

<p>I am wanting to replace the following code. I have a capacitive touch sensor attached to processing that opens up a random image every time the sensor is held, when the sensor is let go this image disappear.</p>

<p>I want to essentially replace the image files with 26 short video clips at 25 frame rate. Im not sure how to change this code to make that happen.</p>

<p>Any help would be great!</p>

<pre><code>import processing.serial.*;

int threshold = 30; 
PImage [] picArray = new PImage [26]; 
Serial myPort;

boolean holdImage=false;
int imgIndex;

void setup() {
  size (500, 500);

  for (int i=0; i&lt;picArray.length; i++)
    picArray[i]=loadImage(i + ".png");

  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.bufferUntil('\n');
}


void draw() {

  background (255, 255, 255); 
  if (holdImage==true) { 
    image(picArray[imgIndex], 0,0);
  }
}


void serialEvent(Serial myPort) {

  String inString = myPort.readStringUntil('\n');

  if (inString != null) {

    inString = trim (inString);
    float[] touches = float (split(inString, ","));

    if (touches.length &gt;=1) {
      int touch1Value = touches[0] &gt;= threshold ? 1: 0;

      if (touch1Value == 1) {
        if (holdImage == false) {
          imgIndex=int(random(picArray.length));
          holdImage=true;
        }
      } else
        holdImage=false;  //RELEASE holder so to detect next usr press event
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to set the starting point of videos?</title>
      <link>https://forum.processing.org/two/discussion/21897/how-to-set-the-starting-point-of-videos</link>
      <pubDate>Sat, 08 Apr 2017 20:58:47 +0000</pubDate>
      <dc:creator>rickymarto</dc:creator>
      <guid isPermaLink="false">21897@/two/discussions</guid>
      <description><![CDATA[<p>I'd like to make a code which play portions of a loaded video, setting the starting point and the duration of those portions of clip. It is a sort of random granular playback.</p>

<p>How can I play a clip from a starting point which is not the beginning of a loaded clip? How can I set the duration of the grains?</p>

<p>I'm using the default video library.</p>

<pre><code>import processing.video.*;

Movie video;

void setup() {
  size(600, 400);
  video = new Movie(this, "station.mov");
  video.loop();
}

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

void draw() {
  image(video, 0, 0);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Frame Accurate Interactive Video Playback - a solution for 1.5.x but not working in 3.x</title>
      <link>https://forum.processing.org/two/discussion/21585/frame-accurate-interactive-video-playback-a-solution-for-1-5-x-but-not-working-in-3-x</link>
      <pubDate>Fri, 24 Mar 2017 16:07:35 +0000</pubDate>
      <dc:creator>chrios1001</dc:creator>
      <guid isPermaLink="false">21585@/two/discussions</guid>
      <description><![CDATA[<p>After much hacking I have made a sketch that does frame accurate interactive video playback.
I based this on tips and code from the older processing forums.
BUT - it only works in processing 1.5.1
I had to use various workarounds, and I don't know why they work.
It is something to do with the conversion from time in seconds to an accurate frame number.
A limitation of the jump() command.</p>

<p>I'm posting this code in the hope that it might help others
and maybe to find a solution that works in Processing 3.x</p>

<p>here's the code with lots of comments and link to a reliable test video:</p>

<pre><code>/*
 An example of frame accurate interactive video playback
 Tested working for frame accurate interactive viewing of videos at 25fps and 30fps - any length.
 This only works in processing 1.5.1
 I cannot get it working in newer versions of Processing
 This is probably due to the switch to the gstreamer library

 Easiest way to check it's working is to use a movie file with the
 correct frame number printed on each frame so you can spot skipping frames
 as you use the keys: -/+ to navigate.

 The suitable video for this sketch (with it's numbered frames) can be d/ld here:
 <a href="http://33dd.com/processing/100_Numbered_frames_30fps.mov" target="_blank" rel="nofollow">http://33dd.com/processing/100_Numbered_frames_30fps.mov</a>
 */

import processing.video.*; 
Movie myMovie; 
float movieFps=30.00;//fps of the movie - please set to match your movie file
float advanceLength = 1/(movieFps-0.01);//get length of one frame in seconds - and subtract 0.01 (why -0.01 I don't know??)
//this movie is 30fps - but sketch is only accurate if we declare fps as 29.99fps - why??

void setup()
{ 
  size(640, 320, P2D);//P2D needed for processing 1.5.--
  //size(640, 320);//use this method in processing 2.++ - no more P2D
  background(0); 

  //load a movie with visible framenumbers - makes it easier to check accuracy
  myMovie = new Movie(this, "100_Numbered_frames_30fps.mov"); //see link at top for video source
  myMovie.loop();//play the movie
  myMovie.speed(0);//best way to stop the movie - pause() halts the thread - so we must use speed(0)
} 

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

void draw()
{ 
  image(myMovie, 0, 0, width, height);
} 

void keyPressed()
{ //use - / +  keys to go back and forward one frame
  if (key == '-')
  {
    if (myMovie.time() &lt; advanceLength)//if movie time &lt; 1 frame jump to start of movie (another hack needed to make it work)
    {
      myMovie.jump((myMovie.time() - advanceLength) % 0);
    } else  
    {//for some reason this only works accurately if we jump backwards then forward one frame
      myMovie.jump((myMovie.time() - advanceLength) % myMovie.duration()); 
      myMovie.jump((myMovie.time() + advanceLength) % myMovie.duration());
    }
  }  
  if (key == '=')
  {
    //jump forward by one frame 
    myMovie.jump((myMovie.time() + advanceLength) % myMovie.duration());
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problems with saving every frame from videostream with dropping framerate</title>
      <link>https://forum.processing.org/two/discussion/21461/problems-with-saving-every-frame-from-videostream-with-dropping-framerate</link>
      <pubDate>Fri, 17 Mar 2017 20:14:16 +0000</pubDate>
      <dc:creator>Per</dc:creator>
      <guid isPermaLink="false">21461@/two/discussions</guid>
      <description><![CDATA[<p>I got a sketch like below. I want to save every frame from the video but the framerate is dropping and processing only process every fourth frame from the videostream and saves it with saveFrame.</p>

<p>How can I process and save every frame?
How can I halt the next frame from the videostream until the frame is processed and saved?</p>

<p>Below is a print of the videoFrame from the videostream and the frame that is saved. As you can see only about every fourth frame is processed and saved</p>

<blockquote class="Quote">
  <p>VideoFrame: 0  FRAMERATE: 18.936382<br />
  savedFrame: 1<br />
  VideoFrame: 1  FRAMERATE: 22.489614<br />
  VideoFrame: 2  FRAMERATE: 22.489614<br />
  VideoFrame: 3  FRAMERATE: 22.489614<br />
  VideoFrame: 4  FRAMERATE: 22.489614<br />
  VideoFrame: 5  FRAMERATE: 22.489614<br />
  VideoFrame: 6  FRAMERATE: 22.489614<br />
  savedFrame: 7<br />
  VideoFrame: 7  FRAMERATE: 20.717686<br />
  VideoFrame: 8  FRAMERATE: 20.717686<br />
  VideoFrame: 9  FRAMERATE: 20.717686<br />
  VideoFrame: 10  FRAMERATE: 20.717686<br />
  savedFrame: 11<br />
  VideoFrame: 11  FRAMERATE: 19.62102<br />
  VideoFrame: 12  FRAMERATE: 19.62102<br />
  savedFrame: 13<br />
  VideoFrame: 13  FRAMERATE: 18.655874<br />
  VideoFrame: 14  FRAMERATE: 18.655874<br />
  VideoFrame: 15  FRAMERATE: 18.655874<br />
  savedFrame: 16<br />
  VideoFrame: 16  FRAMERATE: 17.817186<br />
  VideoFrame: 17  FRAMERATE: 17.817186<br />
  VideoFrame: 18  FRAMERATE: 17.817186<br />
  VideoFrame: 19  FRAMERATE: 17.817186<br />
  savedFrame: 20<br />
  VideoFrame: 20  FRAMERATE: 17.098238<br />
  VideoFrame: 21  FRAMERATE: 17.098238<br />
  savedFrame: 22<br />
  VideoFrame: 22  FRAMERATE: 16.579494<br />
  VideoFrame: 23  FRAMERATE: 16.579494<br /></p>
</blockquote>

<p>Heres my sketch:</p>

<pre><code>import processing.video.*;

Movie m;

int res = 5;
PVector loc;
int frameCounter = 0;
boolean export = false;
int frame = 0;

void settings() {
  size(960, 540);
}

void setup() {
  m = new Movie(this, "video.mp4");
  loc = new PVector(0, 0);
  m.play();
  m.loop();

  background(255);
  ellipseMode(LEFT);
}

void movieEvent(Movie m) {
  if (m.available()) {
    println("VideoFrame: " + frame + "  FRAMERATE: " + frameRate);
    frame++;
    m.read();
  }
}

void draw() {
  println("savedFrame: " + frame);
  run();
}

void run() {
  for (int i = 0; i &lt;  m.width/res; i++) {
    for (int j = 0; j &lt; m.height/res; j++) {
      loc.x = i*res;
      loc.y = j*res;

      color col = m.pixels[(int)loc.x  + (int)loc.y * m.width];
      noStroke();
      fill(col);
      ellipse(loc.x, loc.y, res, res);
    }
  }

  if (export &amp;&amp; frameCounter &lt; 3600) {
    saveFrame("frames/####.png");
    frameCounter++;
  } 

  if (frameCounter &gt; 3598) {
    println("EXPORT KLAR");
  }
}

void keyReleased() {
  println("export"+ export + "  frameRate: " + frameRate + " frameCounter: " + frameCounter);
  if (key == 'e') {
    frameCounter = 0;
    println("export"+ export + "  frameRate: " + frameRate);
    export = !export;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Movie Read (Frame Differencing)</title>
      <link>https://forum.processing.org/two/discussion/16946/movie-read-frame-differencing</link>
      <pubDate>Thu, 02 Jun 2016 07:41:40 +0000</pubDate>
      <dc:creator>Luke12345</dc:creator>
      <guid isPermaLink="false">16946@/two/discussions</guid>
      <description><![CDATA[<p>What's wrong with my code. The video is playable but it is without the frame differencing filter.</p>

<pre><code>import processing.video.*;

int numPixels;
int[] previousFrame;
Movie video;

void setup() {
  size(1920, 1080);

  // This the default video input, see the GettingStartedCapture 
  // example if it creates an error
  video = new Movie(this, "abc.mp4");

  // Start capturing the images from the camera
     video.loop(); 
   //video.read(); 
  numPixels = video.width * video.height;
  // Create an array to store the previously captured frame
  previousFrame = new int[numPixels];
  loadPixels();

}

void draw() {
  if (video.available()) {

    // When using video to manipulate the screen, use video.available() and
    // video.read() inside the draw() method so that it's safe to draw to the screen
    video.read(); // Read the new frame from the camera
    video.loadPixels(); // Make its pixels[] array available
    image(video, 0, 0);
    int movementSum = 0; // Amount of movement in the frame
    for (int i = 0; i &lt; numPixels; i++) { // For each pixel in the video frame...
      color currColor = video.pixels[i];
      color prevColor = previousFrame[i];
      // Extract the red, green, and blue components from current pixel
      int currR = (currColor &gt;&gt; 16) &amp; 0xFF; // Like red(), but faster
      int currG = (currColor &gt;&gt; 8) &amp; 0xFF;
      int currB = currColor &amp; 0xFF;
      // Extract red, green, and blue components from previous pixel
      int prevR = (prevColor &gt;&gt; 16) &amp; 0xFF;
      int prevG = (prevColor &gt;&gt; 8) &amp; 0xFF;
      int prevB = prevColor &amp; 0xFF;
      // Compute the difference of the red, green, and blue values
      int diffR = abs(currR - prevR);
      int diffG = abs(currG - prevG);
      int diffB = abs(currB - prevB);
      // Add these differences to the running tally
      movementSum += diffR + diffG + diffB;
      // Render the difference image to the screen
      pixels[i] = color(diffR, diffG, diffB);
      // The following line is much faster, but more confusing to read
      //pixels[i] = 0xff000000 | (diffR &lt;&lt; 16) | (diffG &lt;&lt; 8) | diffB;
      // Save the current color into the 'previous' buffer
      previousFrame[i] = currColor;
    }
    // To prevent flicker from frames that are all black (no movement),
    // only update the screen if the image has changed.
    if (movementSum &gt; 0) {
      updatePixels();
      println(movementSum); // Print the total amount of movement to the console
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Using Processing + Makey Makey + Conductive Paint to play a video when an object is touched</title>
      <link>https://forum.processing.org/two/discussion/20993/using-processing-makey-makey-conductive-paint-to-play-a-video-when-an-object-is-touched</link>
      <pubDate>Fri, 24 Feb 2017 19:39:41 +0000</pubDate>
      <dc:creator>vvara19</dc:creator>
      <guid isPermaLink="false">20993@/two/discussions</guid>
      <description><![CDATA[<p>Hello all,</p>

<p>I am very new to Processing so would appreciate your help.</p>

<p>I have 4 objects painted with BARE conductive electric paint. I have 4 short video clips for each object. Each object has its own video clip.
I need a video clip to play when an object is being continuously touched, and for it to pause when the hand is taken off the object.</p>

<p>I have connected a Makey Makey + Alligator clips to the conductive painted objects and also the space bar on the makey makey board. I used the paint on the table surface, so when touching this and the painted object the cursor space is moving in a text doc (just to test).</p>

<p>One of my videos is called M1.mov</p>

<p>The code I have at the moment is but I don't know if it is any good?</p>

<p>import processing.video.*;
Movie M1;</p>

<p>void setup() {
  size(640, 360);
  background(255);
  M1 = new Movie(this, "M1.mov");
}</p>

<p>void draw() {
  background(0);
}</p>

<p>void keyPressed() {</p>

<p>if (key == 'r') {
    image(M1, 0, 0);
    println("r");
  }
}</p>

<p>void movieEvent(Movie m) {
  m.read();
}</p>

<p>Many thanks to all who can help,
Vara</p>
]]></description>
   </item>
   <item>
      <title>could not load video</title>
      <link>https://forum.processing.org/two/discussion/20809/could-not-load-video</link>
      <pubDate>Wed, 15 Feb 2017 16:59:42 +0000</pubDate>
      <dc:creator>Anupam</dc:creator>
      <guid isPermaLink="false">20809@/two/discussions</guid>
      <description><![CDATA[<pre><code>        import gab.opencv.*;
        import processing.video.*;

        Movie video;
        OpenCV opencv;

        void setup() {
          size(800, 800);
          video = new Movie(this, "a.mp4");
          opencv = new OpenCV(this, 800, 800);

          opencv.startBackgroundSubtraction(5, 3, 0.5);

          video.loop();
          video.play();
        }

        void draw() {
          image(video, 0, 0);  
          opencv.loadImage(video);

          opencv.updateBackground();

          opencv.dilate();
          opencv.erode();

          noFill();
          stroke(255, 0, 0);
          strokeWeight(3);
          for (Contour contour : opencv.findContours()) {
            contour.draw();
          }
        }

        void movieEvent(Movie m) {
          m.read();
        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to trigger video based on time</title>
      <link>https://forum.processing.org/two/discussion/20746/how-to-trigger-video-based-on-time</link>
      <pubDate>Sat, 11 Feb 2017 10:31:07 +0000</pubDate>
      <dc:creator>ConnorWilson1</dc:creator>
      <guid isPermaLink="false">20746@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>So I've been using Processing for the last couple of weeks, and have been trying to incorporate it in to my final project for University. I've so far created a working clock based on the designs of the old BBC clocks that used to play when the channels shut down for the night, and what I'm looking to do is essentially trigger a video to play at a certain time of the day (on the hour is ideal), play through, finish, return to the clock, and repeat. Now, I have a rough idea of how I could do it, but I want to see if there are any easier ways to go about this than what I was thinking.</p>

<p>Thanks!</p>
]]></description>
   </item>
   </channel>
</rss>