Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Triggering multiple videos / stuttering / poor performance

$
0
0

Bonjour lovely knowledgeable people,

I have a little problem with playing back videos in processing. The aim is to trigger the videos via an serial port input which works fine. The problem is that the videos are played back very laggy. I assume its because they are somehow all played back in the background. The videos are very short 2-5 seconds, but are in HD (1920x1080) and .H264 coded. They are supposed to be played back as long as the input signal is there, and fade to black when its gone. Can you please help me figure out how to avoid this problem and achieve fluid playback of the videos? That would be superb! I Have been hammering over this code for a while and I cant figure it out. Annnd, do you have any idea how to implement fading in and fading out of the videos? Tried it with tint, but can not manage it to do it fast enough. You would be a life saver! Merci, merci bien — any help is appreciated!

Love ❤️ jules

import processing.video.*;
import processing.serial.*;

Movie[]  movie = new Movie[10];
float[] myArray = new float[10];
short videoSpeed= 0 ;
PImage bg;
PImage logo;
short videoID = 9;

String[] video ={ "modellblinker1.mp4",
          "modellblinker2.mp4",
          "modellhood.mp4",
          "modellside2.mp4",
          "modellside1.mp4",
          "modellwindshieldsback.mp4",
          "modellTrunk.mp4",
          "modellwindshieldsback.mp4",
          "modellroof.mp4"};



void setup() {
  fullScreen();
  iniMovies();
  imageMode(CENTER);
  frameRate(25);
  bg = loadImage("1.jpg");
  logo = loadImage("m.png");
  println(Serial.list()[0]);
  myPort = new Serial(this, Serial.list()[0], 19200);
  myPort.bufferUntil('\n');


}
void draw() {
  background(0);
  iniMovies();
  mngMovie();

 if( videoID ==9 ){


    image(logo,-57,-57);//, displayWidth/2, displayHeight/2);

  }else{
    image(movie[videoID], displayWidth / 2, displayHeight / 2);
    if (videoID != 9)
       movie[videoID].loop();
  }
}
void movieEvent(Movie m) {
  m.read();
}
void iniMovies(){
   for (int i = 0 ; i< 9;i++){
       movie[i] =  new Movie(this,video[i]);
   }
}
void mngMovie(){
 // print(myArray);

 if(  myArray[0] >2000.0 ) {  /// blinker link
   if ( videoID != 0  && videoID!=9 )
     movie[videoID].stop();
    movie[0].play();
    videoID = 0;
 }
 else if(  myArray[1]>-4000.0 ) {  // blinker recht
   if ( videoID != 1 && videoID!=9 )
     movie[videoID].stop();
    movie[1].play();
    videoID = 1;
 }

 else if(  myArray[2] <-25000.0  || myArray[2] >17000.0  ) {  //  motor
   if ( videoID != 2  && videoID!=9)
     movie[videoID].stop();
    movie[2].play();
    videoID = 2;
 }

 else if(  myArray[3] >5000.0 ) {  // Tür recht
   if ( videoID != 3 && videoID!=9)
     movie[videoID].stop();
    movie[3].play();
    videoID = 3;
 }

 else if(  myArray[4] >20000.0 ) {  // Tür links
   if ( videoID != 4 && videoID!=9 )
     movie[videoID].stop();
    movie[4].play();
    videoID = 4;
 }

 else if(  myArray[5]>20000.0 || myArray[5]<-25000.0) {   // Windschutz
   if ( videoID != 5 && videoID!=9 )
     movie[videoID].stop();
    movie[5].play();
    videoID = 5;
 }

 else if(  myArray[6] >3000.0 ) { // coffer
   if ( videoID != 6  && videoID!=9)
     movie[videoID].stop();
    movie[6].play();
    videoID = 6;
 }
 else if(  myArray[7] >22000.0|| myArray[7]<-22000.0 ) {  // Fenester hinten
   if ( videoID != 7 && videoID!=9)
     movie[videoID].stop();
    movie[7].play();
    videoID = 7;
 }
 else if(  myArray[8]<-22000.0 ) {  // Dach
   if ( videoID != 8 && videoID!=9  )
     movie[videoID].stop();
    movie[8].play();
    videoID = 8;
 }

 else {
   if( videoID != 9)
       movie[videoID].stop();
  videoID=9;
 }
}
void serialEvent(Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // split the string on the commas and convert the
 // resulting substrings into an integer array:
 try{
  myArray =  float(split(inString, ";"));
  mngMovie();
   for (int i = 0 ; i< 9 ; i++){
     print(myArray[i]);
     print(";");
   }
  println(videoID);
 }
 catch(Exception e){
       // println("Error parsing:");
     //      for (int i = 0 ; i< 9 ; i++){
  //   print(myArray[i]);
  //  print(";");
  // }
   println();
  //println(videoID);
   //     e.printStackTrace();
    }
 }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles