如何从 Android 中的图像数组创建视频? [英] How to create a video from an array of images in Android?

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

问题描述

我想调用一个函数并从图像列表中构建一个视频,然后将其保存在本地设备上:

I want to call a function and build a video out of list of images, and then save it locally on the device:

public void CreateAndSaveVideoFile(List<Bitmap> MyBitmapArray)
{
   // ..
}

试验:

  • Following java/xuggle - encode array of images into a movie, the link in the answer is a dead link

遵循 如何通过编程将图像编码为Java中的视频文件?,接受的答案中建议的库不支持Android.

Following How to encode images into a video file in Java through programming?, The suggested library in the accepted answer does not support Android.

上面的下一个答案为 Android 用户提供了一种方法,但是我不清楚该函数的输入和输出(他从哪里提供图像?他从哪里获得视频?)- 我留下了问题评论

The next answer in the above has an approach for Android users however it is not clear for me the input and the output of that function (where did he give the images? and where did he get the video?) - I left a question comment

上面的下一个答案提供了一个完整的类,但是要包含的所需库的文件已损坏(当我尝试从提供的链接下载它时)- 我留下了问题评论

The next answer in the above provides a whole class, however the required library to be included has a corrupted file (when I try and download it from the provided link) - I left a question comment

遵循 Java:如何从一组图像创建电影?,顶部答案中建议的库使用了我不熟悉的命令,我什至不知道如何使用它们.喜欢:

Following Java: How do I create a movie from an array of images?, the suggested library in the top answer uses commands that I am not familiar with and I don't even know how to use them. Like:

从当前的所有 JPEG 文件创建一个 MPEG-4 文件目录:

Creating an MPEG-4 file from all the JPEG files in the current directory:

mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

我不知道如何在 Java/Android 项目中使用上述内容..

I don't know how can I use the above in a Java / Android project..

任何人都可以帮助指导我或/和为我提供完成任务的方法吗?提前致谢.

Can anyone help in guiding me or/and providing me with an approach to my task? Thanks in advance.

推荐答案

您可以使用 jcodec SequenceEncoder 将图像序列转换为 MP4 文件.

You can use jcodec SequenceEncoder to convert sequence of images to MP4 file.

示例代码:

import org.jcodec.api.awt.SequenceEncoder;
...
SequenceEncoder enc = new SequenceEncoder(new File("filename"));
// GOP size will be supported in 0.2
// enc.getEncoder().setKeyInterval(25);
for(...) {
    BufferedImage image = ... // Obtain an image to encode
    enc.encodeImage(image);
}
enc.finish();

它是一个java库,因此很容易将其导入到Android项目中,您不必像ffmpeg那样使用NDK.

It's a java library so it's easy to import it into Android project, you don't have to use NDK unlike ffmpeg.

参考 http://jcodec.org/ 获取示例代码 &下载.

Refer http://jcodec.org/ for sample code & downloads.

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

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