【发布时间】:2013-08-22 04:09:32
【问题描述】:
我必须在 java 中开发一个从网络摄像头捕获帧的工具,现在我所做的是,我使用 Runtime 类来运行 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:\myfolder\frames\ 和
framesPerSecond 为 10
此代码运行良好,但无法高效抓帧,换句话说我想说它的处理速度很慢,谁能告诉我如何优化它,以便它可以非常快速地抓帧。
我有 Intel Core i3 处理器和 6 GB RAM
我已经检查了许多来自 google 和 stackoverflow 的答案,但这些都不适用于我的情况
【问题讨论】:
-
反对的选民,或者希望结束这个问题的人,请敢把你的cmets。
标签: java ffmpeg video-streaming webcam video-processing