Java 8 here. And while I mention JCodec, that I'm open to any solution that works!
In the JCodec README they provide a decent example for how one can turn a list of BufferedImages
into an MP4 on disk like so:
SeekableByteChannel out = null;
try {
out = NIOUtils.writableFileChannel("/tmp/output.mp4");
// for Android use: AndroidSequenceEncoder
AWTSequenceEncoder encoder = new AWTSequenceEncoder(out, Rational.R(25, 1));
for (...) {
// Generate the image, for Android use Bitmap
BufferedImage image = ...;
// Encode the image
encoder.encodeImage(image);
}
// Finalize the encoding, i.e. clear the buffers, write the header, etc.
encoder.finish();
} finally {
NIOUtils.closeQuietly(out);
}
Instead of writing to a file system resource on the disk (such as "/tmp/output.mp4
"), I'd like to write to a (fully MP4-compliant) in-memory buffer, ideally a byte[]
or something that will convert into a byte[]
.
Is this possible to do with JCodec (maybe something inside of NIOUtils
or similar)?