Recitation 10: Workshops – Audrey Samuel

During this week’s recitation, we were required to attend two separate workshops, one on the map() function hosted by the learning assistants and another of our choice. I chose to attend the Media Manipulation workshop with Jingtian and Linda. I thought it would be helpful to learn more about video editing in Processing as my final project also incorporated videos/images/sounds in Processing. 

Media Manipulation

During the workshop, Jingtian went over how we can upload images and videos onto Processing and how we can manipulate these videos using the various in-built functions. After the presentation, we were asked to complete an exercise which required us to pick a tv show/video and recreate it, whiles also using the map() function. For this exercise, I decided to choose a clip from the Disney Pixar movie “Coco”. I made sure I imported the video library from Processing first and then typed in the code to import the video I had downloaded. Next I wanted to manipulate my video using the functions provided, so I first used the Pixels example code given to us in class. Using this code, I was able to create small  rectangles (size 6) for each Pixel in the movie frame. I had to use a for function for() this line of code and define my int variables as well. I then used the speed() function which sets the relative playback speed of a movie. I thought it would be good to incorporate the map() function here using mouse pressed. If the mouse went farther right within the screen the speed would increase but if it went left it would slow down. This controlled the speed at which the movie was playing, using my mouse. I finally decided to add one more line of code incorporating the jump() function. This function shifts the location of the playback head to a specific time within a movie, similar to the “fast forward” buttons on a t.v. remote. I used keyPressed for this function and so anytime I pressed a key on the keyboard the movie would fast forward. 

Video

Code

import processing.video.*;
Movie myMovie;

void setup() {
  size(640,360);
  frameRate(30);
  myMovie = new Movie(this, "coco1.mp4");
  myMovie.loop();
 
}

void draw() {
  if(myMovie.available()){
    myMovie.read();
  }
  tint(255,150,0);
  image(myMovie, 0,0);
  image(myMovie,width/4,0);
  noStroke();
  int rectSize = 3;
  int w = myMovie.width;
  int h = myMovie.height;
  myMovie.loadPixels();
  for (int y = 0; y<h; y=y+rectSize){
  for (int x = 0; x<w; x=x+rectSize){  
    int i = x + y*w;
    fill(myMovie.pixels[i]);
    rect(x,y,rectSize, rectSize);
  float newSpeed = map(mouseX, 0 , width, 0.1,5);
  myMovie.speed(newSpeed);
}
  }
  myMovie.updatePixels();
}
void keyPressed(){
  myMovie.jump(random(myMovie.duration()));
}

Leave a Reply