Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a video from an array of images in 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) {    // .. } 

Trials:

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

  • Following How to encode images into a video file in Java through programming?, The suggested library in the accepted answer does not support 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

  • 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:

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

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.

like image 451
Khalil Khalaf Avatar asked Oct 29 '16 02:10

Khalil Khalaf


1 Answers

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.

like image 110
Abhishek V Avatar answered Oct 12 '22 08:10

Abhishek V