【问题标题】:How to create mp4 file from bitmap arraylist in Android如何在 Android 中从位图数组列表创建 mp4 文件
【发布时间】:2014-11-18 16:20:17
【问题描述】:

我想从位图数组列表中录制一个 mp4 文件。
我的代码:

File directory = intiFilePath();
DataOutputStream out = new DataOutputStream(new FileOutputStream(directory.getPath()+"/test.mp4"));
int maxBufferSize = 256 * 1024;// 256KB
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
for (Bitmap n : bmpList) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    n.compress(Bitmap.CompressFormat.JPEG, 100, bos);
    byte[] bitmapdata = bos.toByteArray();
    ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
    DataInputStream in = new DataInputStream(bs);
    bytesAvailable = in.available();
    bufferSize = Math.min(bytesAvailable, maxBufferSize);
    buffer = new byte[bufferSize];
    bytesRead = in.read(buffer, 0, bufferSize);
    while (bytesRead > 0) {
        out.write(buffer, 0, bytesRead);
        out.flush();
        bytesAvailable = in.available();
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        bytesRead = in.read(buffer, 0, bufferSize);
    }
    in.close();
}
out.close();

但是mp4文件无法播放(文件存在)。
任何人都可以帮我解决问题。

【问题讨论】:

  • 您将多个 jpg 图像相互附加并希望这成为可播放的视频?
  • 看看这个SO post

标签: android


【解决方案1】:

对不起,你不能。尝试使用 OpenCv 库

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 2016-07-02
    • 2013-12-17
    • 2014-10-22
    相关资源
    最近更新 更多