使用来自 shell 的 Processing-3.2.2

Using Processing-3.2.2 from shell

伙计们,我正在研究音频可视化,并在 pde 中制作了一个成功的 运行 文件。该代码采用 "input.mp3" 然后导出 .mp4 文件。我们可以通过终端(.sh)使用它吗?我的意思是通过编写一些命令来执行程序。喜欢:

processing-3.2.2 filename.pde input.mp3

并生成该输入的视频.mp3。这是我的代码:

import ddf.minim.*;
import ddf.minim.analysis.*;
import com.hamoid.*;

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

void draw()
{ 
  float t = map(mouseX, 0, width, 0, 1);
  beat.detect(player.mix);
  fill(#1A1F18, 20);
  noStroke();
  rect(0, 0, width, height);
  translate(width/2, height/2);
  noFill();
  fill(-1, 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(-1);
    strokeWeight(2);
    point(x2, y2);
    popStyle();
  }
  endShape();
   if (flag) showMeta();
   videoExport.saveFrame();
 }



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==' ')exit();
  if(key=='s')saveFrame("###.jpeg");
}

您不能从命令行或脚本 运行 .pde 文件。

但是您可以将 .pde 文件转换为 Java 应用程序,然后 运行 该 Java 应用程序就像您 运行 任何其他 Java 个应用程序。

第一步,从您的 Processing 编辑器转到 File > Export Application...,这将显示导出选项 window。在那里设置你的选项(可能会玩一下看看每个选项的作用)然后点击 Export 按钮。

这会将应用程序导出到您的草图目录。该应用程序为您提供了各种 .java.jar 文件,您可以将其用作 Java 应用程序。

从那里开始,只需 运行 将 .jar 文件与 运行 任何其他 .jar 文件完全一样。