gpt4 book ai didi

Java 录制屏幕的速度不够快

转载 作者:行者123 更新时间:2023-11-30 11:25:21 24 4
gpt4 key购买 nike

我正在尝试用 Java 制作一个录音程序。我不想使用 JMF(Java 媒体框架)以外的任何外部库。我正在使用两个 Swing 计时器(作为一个 Swing 应用程序),一个用于捕获屏幕并将其添加到队列中,另一个用于将 BufferedImage 从队列中取出并将其写入文件。这是我的计时器:插入队列:

timer = new Timer(1000/FPS, new ActionListener() { //FPS is a user-inputed value from 1-60 by default its 25
@Override
public void actionPerformed(ActionEvent ae) {
executor.execute(new Runnable() { //executor is a java.util.concurrent.Executor;
//I put them in an executor so the timer wouldn't wait for the code to finish
@Override
public void run() {
try {
images.insert(R.createScreenCapture(Screen)); //Images is my own queue & R is a java.awt.Robot
//Screen is a rectangle that is Toolkit.getDefaultToolkit().getScreenSize()
} catch (Exception e) {
ExceptionPrinter.PrintE(e); //This is just a method to print the exception to me
System.out.print(images.length());
timer.stop();
timer2.stop();
} catch (OutOfMemoryError e) { //This is mainly a debug catch
timer.stop();
timer2.stop();
System.out.print(images.length());
e.printStackTrace();
}
}
});
}
});

写入图像:

timer2 = new Timer(1000 / FPS, new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
if (images.length() != 0) {
if (!(new File("C:").getFreeSpace() <= 10000000)) {
String path=AppRunner.AppR3Directory + "VideoTemp" + File.pathSeparator + file + getModifier() + File.pathSeparator + image + ".JPEG";
//AppRunner.AppR3Directory is the working directory of the program (never changes)
//file is the user-inputed filename & getModifier() is either "" or a number above 0 (for when the program auto-starts another record)
ImageIO.write(images.pop(), "JPEG", new java.io.File(path));
imagelist.add(path); //This adds it to my list of images for when i change it to a .mov (custom array)
image++;
} else {
throw new SecurityException("Not enough memory!");
}
}
} catch (IOException e) {
ExceptionPrinter.PrintE(e);
timer.stop();
timer2.stop();
} catch (SecurityException e) {
ExceptionPrinter.PrintE(e);
timer.stop();
timer2.stop();
}
}
});

我的问题是它的记录速度似乎不够快。例如,默认值为 25 FPS,我只能得到 6 FPS。我尝试过更改许多不同的东西并在整个互联网上进行搜索,但我找不到解决方案。我想找出我在让它足够快地记录方面不正确的地方。提前感谢任何解决这个问题的人(我已经坚持了三天)。

编辑:我确实计划将其更改为一个计时器并使用一种方法来写入(由于写入延迟,我最初有两个),如 SimonC 所说。

最佳答案

试试 Monte Media Library screen recorder .我上次测试时得到了很好的结果。

Windows Media Player says it can't open it..

AFAIR WMP 用所有 MOV 表示。相当恼人,因为它声称文件关联。用不是 WMP 的播放器试试。


从长远来看,您会希望将 MOV 转换为另一种格式。使用 JMF 生产的那些巨大。

关于Java 录制屏幕的速度不够快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20296825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com