安卓使从图像列表动画视频 [英] Android make animated video from list of images

查看:178
本文介绍了安卓使从图像列表动画视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过将两幅图像之间的过渡动​​画,使从图像列表中的动画视频。我发现有很多类似的问题就这么喜欢,

I want to make animated video from list of images by applying transition animation between two images. I found many similar questions on SO like,

<一个href="http://stackoverflow.com/questions/9091794/android-screen-capturing-or-make-video-from-images">Android屏幕捕捉,或使从图像视频

<一个href="http://stackoverflow.com/questions/8471212/android-how-to-make-video-using-set-of-images-from-sd-card">Android-如何使用组图像从SD卡进行视频?

所有相似,所以问题的建议使用动画,但是我们怎么可以存储动画图片到视频文件?是否有任何的Andr​​oid库支持此功能来使图像的视频?

All similar SO questions suggest to used animation for that, but how can we store that animated images to video file? Is there any Android library support this facility to make video of images?

任何帮助是AP preciated ... 在此先感谢

Any Help is appreciated...!!! Thanks in Advance

推荐答案

安卓没有为AWT的BufferedBitmap也不AWTUtil支持,这是Java SE。目前与SequenceEn codeR解决方案已经整合成J个codeC的Andr​​oid版本。您可以从包装org.j codec.api.SequenceEn codeR使用它。

Android do not support for AWT's BufferedBitmap nor AWTUtil, that is for Java SE. Currently the solution with SequenceEncoder has been integrated into jcodec's Android version. You can use it from package org.jcodec.api.SequenceEncoder.

下面是使用j个codeC从一系列的位图生成的MP4文件的解决方案:

Here is the solution for generating MP4 file from series of Bitmaps using jcodec:

try {
    File file = this.GetSDPathToFile("", "output.mp4");
    SequenceEncoder encoder = new SequenceEncoder(file);

    // only 5 frames in total
    for (int i = 1; i <= 5; i++) {
        // getting bitmap from drawable path
        int bitmapResId = this.getResources().getIdentifier("image" + i, "drawable", this.getPackageName());
        Bitmap bitmap = this.getBitmapFromResources(this.getResources(), bitmapResId);
        encoder.encodeNativeFrame(this.fromBitmap(bitmap));
    }
    encoder.finish();
} catch (IOException e) {
    e.printStackTrace();
}

// get full SD path
File GetSDPathToFile(String filePatho, String fileName) {
    File extBaseDir = Environment.getExternalStorageDirectory();
    if (filePatho == null || filePatho.length() == 0 || filePatho.charAt(0) != '/')
        filePatho = "/" + filePatho;
    makeDirectory(filePatho);
    File file = new File(extBaseDir.getAbsoluteFile() + filePatho);
    return new File(file.getAbsolutePath() + "/" + fileName);// file;
}

// convert from Bitmap to Picture (jcodec native structure)
public Picture fromBitmap(Bitmap src) {
    Picture dst = Picture.create((int)src.getWidth(), (int)src.getHeight(), ColorSpace.RGB);
    fromBitmap(src, dst);
    return dst;
}

public void fromBitmap(Bitmap src, Picture dst) {
    int[] dstData = dst.getPlaneData(0);
    int[] packed = new int[src.getWidth() * src.getHeight()];

    src.getPixels(packed, 0, src.getWidth(), 0, 0, src.getWidth(), src.getHeight());

    for (int i = 0, srcOff = 0, dstOff = 0; i < src.getHeight(); i++) {
        for (int j = 0; j < src.getWidth(); j++, srcOff++, dstOff += 3) {
            int rgb = packed[srcOff];
            dstData[dstOff]     = (rgb >> 16) & 0xff;
            dstData[dstOff + 1] = (rgb >> 8) & 0xff;
            dstData[dstOff + 2] = rgb & 0xff;
        }
    }
}

在情况下,你需要改变FPS,你可以自定义SequenceEn codeR。

In case you need to change the fps, you may customize the SequenceEncoder.

这篇关于安卓使从图像列表动画视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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