I can't get this to run,because java just waits for ffmpeg. But ffmpeg doesn't give an input- nor an error stream. It just runs, but doing nothing.
The output of "System.out.println("command:.." insert into bash just runs fine as expected.So there is nothing wrong with the ffmpeg syntax.
Here's the code.
package mypackage;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.imageio.ImageIO;
/**
*
* @author test
*/
public class ffmpeg_hang {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, InterruptedException {
String INPUT_FILE="/path/to/media";
String FFMPEG_PATH="/path/to/ffmpegFolder/";
for(int i=0;(i+4)<40;i+=4){
String[] ffmpeg_pipe = new String[]{
FFMPEG_PATH + "ffmpeg_4.1.1",
"-ss",(i+""),"-t", "4",
"-i", INPUT_FILE,
"-ac", "1", "-acodec", "pcm_s16le", "-ar", "16000",
"-f","nut","-","|",
FFMPEG_PATH + "ffmpeg_4.1.1",
"-i","-",
"-lavfi", "showspectrumpic=s=128x75:legend=disabled:saturation=0:stop=8000",
"-f","image2pipe","pipe:1"};
System.out.println("command: "+String.join(" ", ffmpeg_pipe));
Process p;
//ffmpe wav->pipe->spectrogra->pipe->java
p = Runtime.getRuntime().exec(ffmpeg_pipe);
StringBuilder Boxbuffer = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line = "";
while ((line = reader.readLine()) != null) {
Boxbuffer.append(line);
}
System.out.println("ffmpeg errors->> "+Boxbuffer.toString());
p.waitFor();
BufferedImage image = ImageIO.read(p.getInputStream());
//do stuff with image
}
}
}