How to create a video from an array of images in Android?

后端 未结 9 897
时光说笑
时光说笑 2020-12-04 10:32

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

        
9条回答
  •  余生分开走
    2020-12-04 11:19

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

    Sample code :

    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();
    

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

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

提交回复
热议问题