I am trying to transcode a *.mov file into a *.mp4 file using JAVE, which calls ffmpeg. Both input file and output file are in InputStream and OutputStream forms. That means I need to pass InputStream and OutputStream as -i and -y parematers for ffmpeg. How do I do that ?
//Read a movfile.mov converted into a FileInputStream
InputStream fileInputStream = getFileInputStream();
OutputStream fileOutputStream = new FileOutputStrea(outputMP4File) //Output
Process p = Runtime.exec("ffmpeg -i - -y -");
InputStream pInStrm = p.getInputStream();
OutputStream pOutStrm = p.getOutputStream();
int vin = 0, vout = 0;
Thread read = new Thread() {
byte[] buff = new byte[4096];
void run() {
while ((vin=fileInputStream.read(buf))!=-1) {
pOutStrm.write(buf, 0, vin);
}
}
}; read.start();
Thread write = new Thread() {
byte[] buff = new byte[4096];
void run() {
while ((vout=pInStrm.read(buf))!=-1) {
fileOutputStream.write(buf, 0, vout);
}
}
}; write.start();
But I keep getting "IOException: pipe is closed" error. Could somebody help me out ? Alternatively if there is any JAVA API that could do this transcoding(on Windows and RedHat Linux), that would be very helpful
Thanks