Java 中的 ScreenVideo 编码器

发布于 2024-09-18 03:25:35 字数 304 浏览 4 评论 0 原文

有人知道 ScreenVideo(v1 或 v2)的免费 Java 视频编码器吗?我知道 ffmpeg 有一个 C++ 版本,Lee Felarca 用 AS3 编写了一个版本;但我真的很想拥有一个 Java 语言的。
AS3:http://www.zeropointnine.com/blog/assets_code/SimpleFlvWriter。 as.txt

Anyone know of a Java video encoder for ScreenVideo (v1 or v2) which is free? I know ffmpeg has a C++ version and Lee Felarca wrote one in AS3; but I really would like to have one in Java.

AS3: http://www.zeropointnine.com/blog/assets_code/SimpleFlvWriter.as.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浪菊怪哟 2024-09-25 03:25:35

我相信 Xuggle 库可以满足您的需求 - 尽管它实际上可能是一个包装器围绕 ffmpeg 等本机库。

以下是将桌面屏幕截图编码为 flv (mp4) 的示例代码片段:

 final Robot robot = new Robot();
 final Toolkit toolkit = Toolkit.getDefaultToolkit();
 final Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());

 // First, let's make a IMediaWriter to write the file.
 final IMediaWriter writer = ToolFactory.makeWriter("output.mp4");

 // We tell it we're going to add one video stream, with id 0,
 // at position 0, and that it will have a fixed frame rate of
 // FRAME_RATE.
 writer.addVideoStream(0, 0,
     FRAME_RATE,
     screenBounds.width, screenBounds.height);

 // Now, we're going to loop
 long startTime = System.nanoTime();
 for (int index = 0; index < SECONDS_TO_RUN_FOR*FRAME_RATE.getDouble(); index++)
 {
   // take the screen shot
   BufferedImage screen = robot.createScreenCapture(screenBounds);

   // convert to the right image type
   BufferedImage bgrScreen = convertToType(screen,
       BufferedImage.TYPE_3BYTE_BGR);

   // encode the image to stream #0
   writer.encodeVideo(0,bgrScreen,
       System.nanoTime()-startTime, TimeUnit.NANOSECONDS);
    System.out.println("encoded image: " +index);

   // sleep for framerate milliseconds
   Thread.sleep((long) (1000 / FRAME_RATE.getDouble()));
 }
 // Finally we tell the writer to close and write the trailer if
 // needed
 writer.close();

此代码来自此教程 在 Xuggle 网站上。

更高级的编码,也在 Xuggle 网站此处上。

如果您想要原生包装器,请运行网络搜索 "IContainerFormat flv" 用于示例代码的其他位。

另外,已经有一个非常相似的问题


更新:原生java实现

查看 ScreenVideoEncoder.java 来自 github 上的 bigbluebutton 项目。

I believe the Xuggle library does what you want -- although it may actually be a wrapper around native libraries such as ffmpeg.

Here's a snippet of example code encoding desktop screenshots to a flv (mp4):

 final Robot robot = new Robot();
 final Toolkit toolkit = Toolkit.getDefaultToolkit();
 final Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());

 // First, let's make a IMediaWriter to write the file.
 final IMediaWriter writer = ToolFactory.makeWriter("output.mp4");

 // We tell it we're going to add one video stream, with id 0,
 // at position 0, and that it will have a fixed frame rate of
 // FRAME_RATE.
 writer.addVideoStream(0, 0,
     FRAME_RATE,
     screenBounds.width, screenBounds.height);

 // Now, we're going to loop
 long startTime = System.nanoTime();
 for (int index = 0; index < SECONDS_TO_RUN_FOR*FRAME_RATE.getDouble(); index++)
 {
   // take the screen shot
   BufferedImage screen = robot.createScreenCapture(screenBounds);

   // convert to the right image type
   BufferedImage bgrScreen = convertToType(screen,
       BufferedImage.TYPE_3BYTE_BGR);

   // encode the image to stream #0
   writer.encodeVideo(0,bgrScreen,
       System.nanoTime()-startTime, TimeUnit.NANOSECONDS);
    System.out.println("encoded image: " +index);

   // sleep for framerate milliseconds
   Thread.sleep((long) (1000 / FRAME_RATE.getDouble()));
 }
 // Finally we tell the writer to close and write the trailer if
 // needed
 writer.close();

This code is from this tutorial on the Xuggle website.

More advanced encoding, also on the Xuggle website here.

If a native wrapper is what you wanted, run a web search for "IContainerFormat flv" for other bits of example code.

Also, there is already a very similar question


Update: Native java implementation

Check out ScreenVideoEncoder.java from the bigbluebutton project on github.

梦在深巷 2024-09-25 03:25:35

Werner Randelshofer 在他的博客上发布了一个纯 Java 屏幕录像机,并且很友善地发布了源代码:
http://www.randelshofer.ch/blog/2011/ 05/pure-java-screen-recorder/
它看起来可以做你想做的事。

Werner Randelshofer posted a pure java screen recorder on his blog and was kind enough to publish the source :
http://www.randelshofer.ch/blog/2011/05/pure-java-screen-recorder/
It looks to do what you want.

极致的悲 2024-09-25 03:25:35

我相信 BigBlueButton 实现了一个,但我不知道他们是否开源它。检查那里。

I believe BigBlueButton implemented one, but I don't know if they open sourced it. Check there.

梦醒灬来后我 2024-09-25 03:25:35

我不知道您是否发现用纯 Java 编写的任何好东西,而不使用本机代码。视频编码是一项非常耗时的任务,因此通常用“快速”本机代码、C 语言甚至汇编语言编写。视频编码通常使用特殊的 CPU 和 GPU 指令来提高速度 - 这一切都无法从 Java 中获得,因此用 Java 编写生产用途的视频编码器没有什么意义。
如果我是您,我只会采用一些本机解决方案并将其嵌入 JNI、JNA 或 Swig(流行的 Java 到本机连接器)。
如果您需要高可移植性(例如 32 位 Windows、64 位 Windows、32 位 Linux、64 位 Linux),只需为这四个平台编译此本机库并将其嵌入到您的 JAR 中即可。
如果您只需要编写未压缩的视频,则可以轻松地用 Java 完成,并且速度将与本机代码一样快。只需将这个 SimpleFlvWriter.as 您发布的内容重写为 Java - 这应该不是一项艰巨的任务。

I don't know if you find anything good written in pure Java, without using native code. Video encoding is a very time-consuming task, so it's usually written in 'fast' native code, in languages like C or even Assembler. Video encoding often uses special CPU and GPU instructions to improve the speed - it all is unavailable from Java, so it makes very little sense to write production-use video encoders in Java.
If I were you, I would just take some native solution and embed it with JNI, JNA or Swig (popular Java-to-native connectors).
If you need high portability (eg. 32-bit Windows, 64-bit Windows, 32-bit Linux, 64-bit Linux), just compile this native library for for those four platforms and embed in your JARs.
If you just need to write uncompressed video, it can be easily done in Java, and it will be as fast as native code. Just take this SimpleFlvWriter.as you posted and rewrite it to Java - it shouldn't be a hard task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文