Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>Here is the solution for generating MP4 file from series of Bitmaps using jcodec:</p> <pre><code>try { File file = this.GetSDPathToFile("", "output.mp4"); SequenceEncoder encoder = new SequenceEncoder(file); // only 5 frames in total for (int i = 1; i &lt;= 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 &lt; src.getHeight(); i++) { for (int j = 0; j &lt; src.getWidth(); j++, srcOff++, dstOff += 3) { int rgb = packed[srcOff]; dstData[dstOff] = (rgb &gt;&gt; 16) &amp; 0xff; dstData[dstOff + 1] = (rgb &gt;&gt; 8) &amp; 0xff; dstData[dstOff + 2] = rgb &amp; 0xff; } } } </code></pre> <p>In case you need to change the fps, you may customize the SequenceEncoder.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload