从处理中导出视频3

时间:2016-11-04 15:46:31

标签: audio video processing visualization

我正在使用processing-3.2.2进行音频可视化。我有代码来播放可视化工具,但我不知道如何将其保存为视频(.mp4)文件。

这是我写的:

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;
int  r = 200;
float rad = 70;
void setup()
{
  size(500, 500);
  //size(600, 400);
  minim = new Minim(this);
  player = minim.loadFile("son_final.mp3");
  meta = player.getMetaData();
  beat = new BeatDetect();
  player.play();
  //player.play();
  background(-1);
  noCursor();
}

void draw()
{ 
  float t = map(mouseX, 0, width, 0, 1);
  beat.detect(player.mix);
  fill(#1A1F18,50);
  noStroke();
  rect(0, 0, width, height);
  translate(width/2, height/2);
  noFill();
  fill(-2, 10);
  if (beat.isOnset()) rad = rad*0.9;
  else rad = 70;
  ellipse(0, 0, 2*rad, 2*rad);
  stroke(-1, 50);
  int bsize = player.bufferSize();
  for (int i = 0; i < bsize - 1; i+=5)
  {
    float x = (r)*cos(i*2*PI/bsize);
    float y = (r)*sin(i*2*PI/bsize);
    float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
    float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
    line(x, y, x2, y2);
  }
  beginShape();
  noFill();
  stroke(-1, 50);
  for (int i = 0; i < bsize; i+=30)
  {
    float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
    float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
    vertex(x2, y2);
    pushStyle();
    stroke(-5);
    strokeWeight(2);
    point(x2, y2);
    popStyle();
  }
  endShape();
   if (flag) showMeta();
}


void showMeta() {
  int time =  meta.length();
  textSize(50);
  textAlign(CENTER);
  text( (int)(time/1000-millis()/1000)/60 + ":"+ (time/1000-millis()/1000)%60, -7, 21);
}

boolean flag =false;
void mousePressed() {
  if (dist(mouseX, mouseY, width/2, height/2)<150) flag =!flag;
}

void keyPressed() {
  if(key=='e')exit();
}

我知道我可以导入MovieMaker库,但我不知道如何在此代码中使用它。请提出一些改变。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用视频导出库。更多信息:http://funprogramming.org/VideoExport-for-Processing/

然后您要做的就是创建VideoExport的实例,然后在videoExport.saveFrame()函数的末尾调用draw()

import com.hamoid.*;

VideoExport videoExport;

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

  videoExport = new VideoExport(this, "basic.mp4");
}
void draw() {
  background(#224488);
  rect(frameCount * frameCount % width, 0, 40, height);

  videoExport.saveFrame();
}

网上有大量资源。我推荐使用谷歌搜索&#34;处理视频导出&#34;大量的结果。然后尝试一下并发布一个MCVE(而不是整个项目),准确显示你被卡住的地方。