Java:如何从一组图像创建电影? [英] Java: How do I create a movie from an array of images?

查看:51
本文介绍了Java:如何从一组图像创建电影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上有一个字节矩阵.每行(意思是 byte[])代表一个图像.如何从中创建电影(任何格式 - avi、mpeg 等),并将其另存为文件?每个图像可以是以下之一:

I basically have an matrix of bytes. Each row (meaning byte[]) represents an image. How do I create a movie out of that (any format - avi, mpeg, whatever), and save it as a file? Each image can be one of the following:

int JPEG    Encoded formats.
int NV16    YCbCr format, used for video.
int NV21    YCrCb format used for images, which uses the NV21 encoding format.
int RGB_565 RGB format used for pictures encoded as RGB_565.
int YUY2    YCbCr format used for images, which uses YUYV (YUY2) encoding format.
int YV12    Android YUV format: This format is exposed to software decoders and applications.

我可以选择任何我喜欢的格式,只要我能制作电影.

I can choose the format to whatever I like, as long as I get to create the movie.

public void createMovie(byte[][] images) {
  // and ideas on what to write here?
}

我不需要实际的实现,只要让我知道想法和我需要的外部库(如果我需要的话).

I don't need the actual implementation, just let me know the idea and what external libraries I need (if I need any).

我还需要在创建电影之前编辑一些图像(字节流)(添加一些文本).我该怎么做?

I also need to edit some of the images (the byte stream) before I create the movie (to add some text). How can I do that?

解决方案必须是仅限 Java"!没有外部程序,没有外部命令(但我可以使用外部 jars).

The solution needs to be "Java only"! No external programs, no external commands (but I can use external jars).

谢谢!

推荐答案

解决方案似乎是使用 Mencoder(或者至少,这似乎是一个半受欢迎的选择).

The solution seems to be to use Mencoder (or at least, that seems to be a semi-popular choice).

这是一个专门针对 images-to- 的链接Mencoder 中的电影功能.

Here's a link that specifically addresses images-to-movies capabilities in Mencoder.

至于在将文本编码为视频的一部分之前将文本渲染到帧上,您可以使用 Java2D 的图像处理库预先在图像上简单地绘制文本例如:

As for rendering text onto the frames before encoding them as part of the video, you can use Java2D's image manipulation libraries to simply draw text on top of the images beforehand For example:

  • Load up the images into BufferedImage objects via the ImageIO library's .read method
  • Use Graphics2D's .drawString method to render the text

这是一种方法,此常见问题解答应该可以帮助您开始使用 Java2D、字体渲染等,并提供指向更多资源的指针.

That's one way to do it, and this FAQ should get you started in that direction with Java2D, font rendering, etc., and offer pointers to further resources.

ImageIO 库还允许您读/写多种图像格式,有效地允许您从 .jpg -> BufferedImage -> .png 或任何您需要的方式对图像进行转码,如果您想在转换过程中临时存储图像文件,和/或在为转换项目导入图像时将所有图像转换为单一格式等.

The ImageIO library also allows you to read/write a number of image formats, effectively allowing you to transcode images from, say, .jpg -> BufferedImage -> .png, or any which way you need to do it, if you want to store the image files temporarily during the conversion process, and/or convert all the images to a single format when importing them for the conversion project, etc.

根据您想要支持的输出格式的数量,您可能会执行类似的操作

Depending on how many output formats you want to support, you'll probably do something like

public void createMovie(BufferedImage[] frames, String destinationFormat)

...其中destinationFormat"类似于m4v"、mpeg2"、h.264"、gif"等

...where "destinationFormat" is something like "m4v", "mpeg2", "h.264", "gif", etc.

这篇关于Java:如何从一组图像创建电影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆