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

查看:179
本文介绍了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!没有外部程序,没有外部命令(但我可以使用外部jar)。

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).

这是一个专门针对图像到电影功能。

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天全站免登陆