我正在尝试使用调用 ffmpeg 的 JAVE 将 *.mov 文件转码为 *.mp4 文件。输入文件和输出文件都是 InputStream 和 OutputStream 的形式。这意味着我需要将 InputStream 和 OutputStream 作为 -i 和 -y 参数传递给 ffmpeg。我怎么做 ?
//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();
但我不断收到“IOException:管道已关闭”错误。有人可以帮帮我吗?或者,如果有任何 JAVA API 可以进行这种转码(在 Windows 和 RedHat Linux 上),那将非常有帮助
谢谢