2016-11-04 74 views
0

我正在使用processing-3.2.2進行音頻可視化。我有代碼來播放可視化工具,但我不知道如何將其保存爲視頻(.mp4)文件。從處理中導出視頻3

這是我寫的:

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

我知道我可以導入製片人庫,但我不知道如何在這段代碼中使用它。請提出一些更改。

謝謝。

回答

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

網上有很多資源。我建議使用Google搜索「處理視頻導出」獲得大量結果。然後嘗試一下併發佈一個MCVE(而不是整個項目),確切地顯示您卡住的位置。

+0

嘿@KevinWorkman我做了更改,它不會導出.mp4視頻文件,但沒有音頻! – Shivams334

+0

@ShivamSharma我真的推薦做一些研究。谷歌「處理視頻導出聲音」,看看其他人是如何做到的。嘗試一下,然後發佈一個特定的問題,如果你卡住了。祝你好運。 –