通过 java 执行 mp4box cmd 出错
Execute mp4box cmd via java got error
抱歉,当我标记 ffmpeg 时,因为我无法标记 MP4Box.But 我也有通过 javacode 使用 ffmpeg 执行的问题。
我在 How to execute cmd commands via Java 阅读,但找不到我的问题。
我在 cmd 中测试了命令,没问题:
MP4Box -dash 10000 -dash-profile live -segment-name output- seg -rap
-bs-switching no input.mp4
但是当我通过 java 代码执行 cmd 时,出现错误:
Error - only one input file found as argument, please check usage
下面是我的代码,有问题吗?
package com.uit.reformatvideo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Logger;
public class ExecuteComandToFormatVideo {
public final static String LINK_MP4BOX = "C:/MP4Box/Tools/MP4Box.exe";
public final static String CREATE_MPD_ECLIPSE = "mp4box -dash 10000 -frag 1000 -rap -bs-switching no";
public final static String CREATE_MPD_IE = "MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no";
private static final Logger log = Logger.getLogger(ExecuteComandToFormatVideo.class.getName());
public static void main(String[] args) throws IOException, InterruptedException {
String s = null;
try {
// run the Unix "ps -ef" command
// using the Runtime exec method:
String lsCmd[] = new String [2];
lsCmd[0] = LINK_MP4BOX;
lsCmd[1] = "MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no input.mp4";
Process p = Runtime.getRuntime().exec(lsCmd);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
}
这是输出:
Here is the standard output of the command:
Here is the standarderror of the command (if any): Error - only one
input file found as argument, please check usage
对不起,因为我的英语不好。我创建了一个 bat 文件,其中包含诸如 CMD 之类的命令,然后我使用 Runtime.getRuntime().exec(url+name+".bat");
执行bat文件。这是我的解决方案。
我的 bat 文件:
cd C:/MP4Box/Tools/
MP4Box
MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no "C:\Users\ducth\Desktop\New folder (2)\SharingVideo\src\main\webapp\resources\video\output.mp4"
抱歉,当我标记 ffmpeg 时,因为我无法标记 MP4Box.But 我也有通过 javacode 使用 ffmpeg 执行的问题。 我在 How to execute cmd commands via Java 阅读,但找不到我的问题。
我在 cmd 中测试了命令,没问题:
MP4Box -dash 10000 -dash-profile live -segment-name output- seg -rap -bs-switching no input.mp4
但是当我通过 java 代码执行 cmd 时,出现错误:
Error - only one input file found as argument, please check usage
下面是我的代码,有问题吗?
package com.uit.reformatvideo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Logger;
public class ExecuteComandToFormatVideo {
public final static String LINK_MP4BOX = "C:/MP4Box/Tools/MP4Box.exe";
public final static String CREATE_MPD_ECLIPSE = "mp4box -dash 10000 -frag 1000 -rap -bs-switching no";
public final static String CREATE_MPD_IE = "MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no";
private static final Logger log = Logger.getLogger(ExecuteComandToFormatVideo.class.getName());
public static void main(String[] args) throws IOException, InterruptedException {
String s = null;
try {
// run the Unix "ps -ef" command
// using the Runtime exec method:
String lsCmd[] = new String [2];
lsCmd[0] = LINK_MP4BOX;
lsCmd[1] = "MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no input.mp4";
Process p = Runtime.getRuntime().exec(lsCmd);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
}
这是输出:
Here is the standard output of the command:
Here is the standarderror of the command (if any): Error - only one input file found as argument, please check usage
对不起,因为我的英语不好。我创建了一个 bat 文件,其中包含诸如 CMD 之类的命令,然后我使用 Runtime.getRuntime().exec(url+name+".bat");
执行bat文件。这是我的解决方案。
我的 bat 文件:
cd C:/MP4Box/Tools/
MP4Box
MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no "C:\Users\ducth\Desktop\New folder (2)\SharingVideo\src\main\webapp\resources\video\output.mp4"