我必须用java开发一个工具来从摄像头中捕获帧,现在我所做的就是,我已经使用运行时类来运行ffmpeg和其他命令,当它开始从我的网络摄像头中捕获帧时,我使用的是以下方法。
public class FFMPEGClass {
private String ffmpegExeLocation, line;
private final String FRAME_DIGITS = "010";
public FFMPEGClass(String capturingDName, String outputImagesLocation, int framesPerSecond) {
ffmpegExeLocation = System.getProperty("user.dir") + "\\bin\\";
System.out.println(ffmpegExeLocation);
try {
System.out.println(ffmpegExeLocation + "ffmpeg -t 100000 "
+ "-f vfwcap -s 640x480 -i 0 -r 1/" + framesPerSecond + " -f image2 " + outputImagesLocation + "\\camera%"+FRAME_DIGITS+"d.jpg");
Process pp = Runtime.getRuntime().exec(ffmpegExeLocation + "ffmpeg -t 100000 "
+ "-f vfwcap -s 640x480 -i 0 -r 1/" + framesPerSecond + " -f image2 " + outputImagesLocation + "\\camera%"+FRAME_DIGITS+"d.jpg");
BufferedReader br = new BufferedReader(new InputStreamReader(pp.getErrorStream()));
while((line = br.readLine()) != null){
System.out.println(line);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}在我的例子中,capturingDName是USB2.0 UVC VGA WebCam
outputImagesLocation是**e:\my文件夹\frames**和
framesPerSecond是10
这段代码运行良好,但无法有效地捕获帧,换句话说,我想说它的处理非常慢,请告诉我如何优化它,以便它能够非常快地捕获帧。
我有Intel Core i3处理器和6 GB of RAM
,我已经检查了许多来自google和stackoverflow的答案,但是在我的例子中,是行不通的。
发布于 2013-08-22 11:22:56
如果使用10 fro frameperseconds,请执行以下调用
Process pp = Runtime.getRuntime().exec(ffmpegExeLocation + "ffmpeg -t 100000 "
+ "-f vfwcap -s 640x480 -i 0 -r 1/" + framesPerSecond + " -f image2 " + outputImagesLocation + "\\camera%"+FRAME_DIGITS+"d.jpg");将扩展到如下内容:
ffmpeg -t 100000 -f vfwcap -s 640x480 -i 0 -r 1/10 -f image2 output%05d.jpg使用-r选项的方式是错误的(参见ffmpeg医生),如果您希望每秒10帧,更新代码以删除小数!
Process pp = Runtime.getRuntime().exec(ffmpegExeLocation + "ffmpeg -t 100000 "
+ "-f vfwcap -s 640x480 -i 0 -r " + framesPerSecond + " -f image2 " + outputImagesLocation + "\\camera%"+FRAME_DIGITS+"d.jpg");https://stackoverflow.com/questions/18329444
复制相似问题