Pradhvan Bisht Pradhvan Bisht - 28 days ago 19
Bash Question

Using Processing-3.2.2 from shell

guys, I am working on audio visualization and made a successful running file in pde. The code takes an "input.mp3" then export the .mp4 file. Can it be possible that we can use it through the terminal(.sh)? I mean with writing some command it executes the program. like:

processing-3.2.2 filename.pde input.mp3


And it produces the video of that input.mp3. Here's my code:

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");
}

Answer

You can't run a .pde file from the command line or from a script.

But you can convert the .pde file into a Java application, and then run that Java application just like you'd run any other Java application.

As a first step, from your Processing editor, go to File > Export Application... which brings up the Export Options window. Set your options there (might play around a bit to see what each option does) and then click the Export button.

That will export the application to your sketch directory. That application gives you various .java and .jar files that you can use as a Java application.

From there it's just a matter of running the .jar files exactly like you'd run any other .jar file.

Comments