【Processing入门】第九章:视频音频

1.播放视频文件

/**
 * Loop. 
 * 
 * Shows how to load and play a QuickTime movie file.  
 *
 */

import processing.video.*;

Movie movie;

void setup() {
  size(640, 360);
  background(0);
  // Load and play the video in a loop
  movie = new Movie(this, "transit.mov");
  movie.loop();
}

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

void draw() {
  //if (movie.available() == true) {
  //  movie.read(); 
  //}
  image(movie, 0, 0, width, height);
}


【Processing入门】第九章:视频音频_第1张图片

 

2.实时视频输入

import processing.video.*;
Capture video;

void setup()
{
  size(320,240);
  video=new Capture(this,320,240,15);
}

void draw()
{
  if(video.available())
  {
    video.read();
  }
  image(video,0,0);
}


或者使用captureEvent()

import processing.video.*;
Capture video;

void setup()
{
  size(320,240);
  video=new Capture(this,width,height,15);
}

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

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


3.音频

3.1 播放音频

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

AudioPlayer player;
Minim minim;

void setup()
{
  size(300,300);
  minim = new Minim(this);
  player=minim.loadFile("1.mp3",1024);
  player.play();
}

void draw()
{
  
}

void stop()
{
  player.close();
  minim.stop();
  super.stop();
}

 

3.2 声音的可视化

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

AudioPlayer player;
Minim minim;

void setup()
{
  size(512,400);
  minim = new Minim(this);
  player=minim.loadFile("1.mp3",1024);
  player.play();
}

void draw()
{
  background(0);
  stroke(255);
  
  for(int i = 0;i

【Processing入门】第九章:视频音频_第2张图片

 

关键部分改为

  for(int i = 0;i

【Processing入门】第九章:视频音频_第3张图片

 

3.3音频输入互动

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioInput in;

void setup()
{
  size(1024,400);
  smooth();
   minim = new Minim(this);
   minim.debugOn();
   in = minim.getLineIn(Minim.STEREO,1024);
   background(0);
   
}

void draw()
{
  fill(0,5);
  rect(0,0,width,height);
  noStroke();
  for(int i = 0;i

【Processing入门】第九章:视频音频_第4张图片

 



 

 

 


 

你可能感兴趣的:(Processing)