Java 小程序截屏到视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2059309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java applet screen capture to a video
提问by Obaid
I wanted to find out how can one capture screencast using java. I know that using Robot class one can get a screenshot but how do I go about capturing it as a video and then uploading it to the server? How exactly would that work?
我想知道如何使用 java 捕获截屏视频。我知道使用 Robot class one 可以获得屏幕截图,但是我如何将其捕获为视频,然后将其上传到服务器?那究竟如何运作?
ideas?
想法?
采纳答案by jarnbjo
With a pure Java solution, I doubt that it will work, but it depends of course on what your interpretation of "video".
使用纯 Java 解决方案,我怀疑它是否可行,但这当然取决于您对“视频”的解释。
On my desktop with a 1920x1200 resolution, I am able to get about 20 frames per second when using the Java Robot to capture the entire screen. Since each image contains >6 MByte of uncompressed data, I would need more than 1 Gbps bandwidth to transmit the raw data of these images to a server. Most probably, requiring so much bandwidth is not acceptable, so you either have to decrease the number of frames per second or apply some kind of compression to the images.
在分辨率为 1920x1200 的桌面上,当使用 Java Robot 捕获整个屏幕时,我能够每秒获得大约 20 帧。由于每个图像包含 >6 MB 的未压缩数据,我需要超过 1 Gbps 的带宽才能将这些图像的原始数据传输到服务器。最有可能的是,需要如此多的带宽是不可接受的,因此您必须减少每秒的帧数或对图像应用某种压缩。
One possibility is to compress each image using one of the image formats supported by ImageIO. The size of the compressed images will of course depend heavily on what is actually shown on the screen, but the performance of the compressors is not particularly good. Compressing to PNG ought to give the best lossless compression ratio for most desktop content, but at least my computer is only able to process just about 2 frames per second. Using the JPEG compressor with default quality settings reaches about 5 frames per second.
一种可能性是使用 ImageIO 支持的一种图像格式来压缩每个图像。压缩图像的大小当然在很大程度上取决于屏幕上实际显示的内容,但压缩器的性能并不是特别好。压缩为 PNG 应该可以为大多数桌面内容提供最佳的无损压缩率,但至少我的计算机每秒只能处理大约 2 帧。使用具有默认质量设置的 JPEG 压缩器可达到每秒约 5 帧。
Using common video codecs through an abstraction layer like jffmpegwill probably achieve both better performance and better compression ratio, but I doubt that mainstream video codecs like WMV or H.264 are suitable for common desktop content.
通过像jffmpeg这样的抽象层使用常见的视频编解码器可能会获得更好的性能和更好的压缩率,但我怀疑 WMV 或 H.264 等主流视频编解码器是否适用于常见的桌面内容。
If you really require a pure Java solution (and are not able to use any of the available standalone software, which do what you're asking for), I would make an attempt to implement my own, simple compression algorithm. With common desktop activity, there ought to be very little difference between most consecutive screen shots, so what might work quite well is to transmit the first frame completely and after that implement an algorithm to roughly detect rectangles, in which changes have been made and then transmit only these combined with JPG or preferrably (quality) PNG compression.
如果您真的需要纯 Java 解决方案(并且无法使用任何可用的独立软件来满足您的要求),我会尝试实现我自己的简单压缩算法。对于常见的桌面活动,大多数连续屏幕截图之间的差异应该很小,因此可能会很好地完成传输第一帧,然后实现算法来粗略地检测矩形,其中已进行更改,然后仅传输这些与 JPG 或最好(质量)PNG 压缩相结合的文件。
回答by Art Clarke
Or use Xuggler, a better wrapper for FFmpeg in Java. In fact, the code for capturing the screen and encoding the video is one of the standard tutorials.
或者使用 Xuggler,一个更好的 Java FFmpeg 包装器。事实上,截屏和编码视频的代码是标准教程之一。
回答by alex
I'm also curious about this. https://www.screencast.com/is currently doing just this with a pure java (or at least straight out of the browser) experience.
我也对这个很好奇。https://www.screencast.com/目前正在使用纯 Java(或至少直接脱离浏览器)体验来执行此操作。
回答by David
You can just use something like Java to a native FFMPEG build, and execute the command line at runtime. Here is an applet that I made that does just that: http://have2chat.net/screencast/
您可以将 Java 之类的东西用于本机 FFMPEG 构建,并在运行时执行命令行。这是我制作的一个小程序,它就是这样做的:http: //have2chat.net/screencast/
回答by NewJavaProgrammer
I have downloaded the main capture *.JARfile for the Screencast-O-Matic.com. To download the file:
我已经下载*.JAR了Screencast-O-Matic.com的主要捕获文件。下载文件:
- Go to http://screencast-o-matic.com/jars/ScreencastOMaticRun-1.0.5.jar
- Save the file
- Extract the contents (I DO NOTintend to use this commercially!)
- 转到http://screencast-o-matic.com/jars/ScreencastOmaticRun-1.0.5.jar
- 保存文件
- 提取内容(我不打算将其用于商业用途!)

