我使用过Xuggler教程来解码和播放视频。 我需要查看每个帧的原始数据。 我使用方法getData如下:
IBuffer img = picture.getData();
如何在Java中将IBuffer img转换为字节数组?
由于
修改
我找到了以下命令:
java.nio.ByteBuffer buffer = img.getByteBuffer(0, bufSize);//bytebuffer
byte[] bytes = new byte[10]; // Create a byte array
ByteBuffer buf=buffer.wrap(bytes); // Wrap a byte array into a buffer
bytes = new byte[buf.remaining()]; // Retrieve bytes between the position and limit
// (see Putting Bytes into a ByteBuffer)
buf.get(bytes, 0, bytes.length); // transfer bytes from this buffer into the given destination array
buf.clear(); // Retrieve all bytes in the buffer
bytes = new byte[buf.capacity()];
// transfer bytes from this buffer into the given destination array
buf.get(bytes, 0, bytes.length);
System.out.println(bytes);
输出为:
[B @ 1ccd51b
[B @ 215eee
[B @ 1e579dc
[B @ 14793a8
[B @ 1082746
.....
它们的长度不同。这是对的吗?
我用过:
System.out.println(Arrays.toString(bytes));
打印出字节数组内容,但输出如下:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
我该如何解决这个问题?
感谢