有人知道ScreenVideo(v1或v2)的Java视频编码器是免费的吗?我知道ffmpeg有一个C++版本,Lee Felarca在AS3中写了一个; 但我真的很想在Java中有一个.
AS3:http://www.zeropointnine.com/blog/assets_code/SimpleFlvWriter.as.txt
我相信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();
Run Code Online (Sandbox Code Playgroud)
此代码来自Xuggle网站上的本教程.
更高级的编码,也在这里的Xuggle网站上.
如果您想要一个原生包装器,请为其他位示例代码运行"IContainerFormat flv"的Web搜索.
此外,还有一个非常相似的问题
更新:本机java实现
从github上的bigbluebutton项目中查看ScreenVideoEncoder.java.
| 归档时间: |
|
| 查看次数: |
2270 次 |
| 最近记录: |