我需要将多个图像(其中我有完整的路径)编码成android上某个FPS的视频。
试验: How to create a video from an array of images in Android?
为什么我无法让它工作: 我将 Jcodec Dependecy 添加到 gradle 文件(
compile 'org.jcodec:jcodec:0.2.3'
compile 'org.jcodec:jcodec-android:0.2.2'
)
然后我将代码粘贴到一个函数中,这就是我得到的结果: 如您所见,我成功导入了 SequenceEncoder (import org.jcodec.api.SequenceEncoder;) 但它无法识别缓冲图像(我认为这是因为我必须使用位图)
它在 SequenceEncoder 中给了我一个错误。
也无法识别encodeImage方法。
然后我尝试使用在 JCodec 网站上找到的代码:
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);
}
但是它无法识别AWTSequenceEncoder,因此方法encodeImage 和finish。
我做错了什么?
最佳答案
好的,我找到了问题的答案,从技术上讲,它就在这个问题的答案中: How to create a video from an array of images in Android?
但是只有两票,尽管它是唯一对我有用的票,也是我发现唯一应该有用的票。你不能在android中使用BufferedImages,而投票最多的问题却可以,并且我没有找到的SequenceEncoder被替换为AndroidSequenceEncoder。
关于java - 将图像编码为视频时出现 JCodec 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52168452/