安卓获取摄像头帧率_android如何获取远程摄像头的rtmp流,并且截取每一帧图片?...

class I420ExternalRender implements NTExternalRender {

// public static final int NT_FRAME_FORMAT_RGBA = 1; // public static final int NT_FRAME_FORMAT_ABGR = 2; // public static final int NT_FRAME_FORMAT_I420 = 3;

private int width_ = 0;

private int height_ = 0;

private int y_row_bytes_ = 0;

private int u_row_bytes_ = 0;

private int v_row_bytes_ = 0;

private ByteBuffer y_buffer_ = null;

private ByteBuffer u_buffer_ = null;

private ByteBuffer v_buffer_ = null;

@Override

public int getNTFrameFormat() {

Log.i(TAG, "I420ExternalRender::getNTFrameFormat return "

+ NT_FRAME_FORMAT_I420);

return NT_FRAME_FORMAT_I420;

}

@Override

public void onNTFrameSizeChanged(int width, int height) {

width_ = width;

height_ = height;

y_row_bytes_ = (width_ + 15) & (~15);

u_row_bytes_ = ((width_ + 1) / 2 + 15) & (~15);

v_row_bytes_ = ((width_ + 1) / 2 + 15) & (~15);

y_buffer_ = ByteBuffer.allocateDirect(y_row_bytes_ * height_);

u_buffer_ = ByteBuffer.allocateDirect(u_row_bytes_

* ((height_ + 1) / 2));

v_buffer_ = ByteBuffer.allocateDirect(v_row_bytes_

* ((height_ + 1) / 2));

Log.i(TAG, "I420ExternalRender::onNTFrameSizeChanged width_="

+ width_ + " height_=" + height_ + " y_row_bytes_="

+ y_row_bytes_ + " u_row_bytes_=" + u_row_bytes_

+ " v_row_bytes_=" + v_row_bytes_);

}

@Override

public ByteBuffer getNTPlaneByteBuffer(int index) {

if (index == 0) {

return y_buffer_;

} else if (index == 1) {

return u_buffer_;

} else if (index == 2) {

return v_buffer_;

} else {

Log.e(TAG, "I420ExternalRender::getNTPlaneByteBuffer index error:" + index);

return null;

}

}

@Override

public int getNTPlanePerRowBytes(int index) {

if (index == 0) {

return y_row_bytes_;

} else if (index == 1) {

return u_row_bytes_;

} else if (index == 2) {

return v_row_bytes_;

} else {

Log.e(TAG, "I420ExternalRender::getNTPlanePerRowBytes index error:" + index);

return 0;

}

}

public void onNTRenderFrame(int width, int height, long timestamp) {

if (y_buffer_ == null)

return;

if (u_buffer_ == null)

return;

if (v_buffer_ == null)

return;

y_buffer_.rewind();

u_buffer_.rewind();

v_buffer_.rewind();

/*if ( !is_saved_image ){is_saved_image = true;int y_len = y_row_bytes_*height_;int u_len = u_row_bytes_*((height_+1)/2);int v_len = v_row_bytes_*((height_+1)/2);int data_len = y_len + (y_row_bytes_*((height_+1)/2));byte[] nv21_data = new byte[data_len];byte[] u_data = new byte[u_len];byte[] v_data = new byte[v_len];y_buffer_.get(nv21_data, 0, y_len);u_buffer_.get(u_data, 0, u_len);v_buffer_.get(v_data, 0, v_len);int[] strides = new int[2];strides[0] = y_row_bytes_;strides[1] = y_row_bytes_;int loop_row_c = ((height_+1)/2);int loop_c = ((width_+1)/2);int dst_row = y_len;int src_v_row = 0;int src_u_row = 0;for ( int i = 0; i < loop_row_c; ++i){int dst_pos = dst_row;for ( int j = 0; j

Log.i(TAG, "I420ExternalRender::onNTRenderFrame w=" + width + " h=" + height + " timestamp=" + timestamp);

// copy buffer

// test // byte[] test_buffer = new byte[16]; // y_buffer_.get(test_buffer);

// Log.i(TAG, "I420ExternalRender::onNTRenderFrame y data:" + bytesToHexString(test_buffer));

// u_buffer_.get(test_buffer); // Log.i(TAG, "I420ExternalRender::onNTRenderFrame u data:" + bytesToHexString(test_buffer));

// v_buffer_.get(test_buffer); // Log.i(TAG, "I420ExternalRender::onNTRenderFrame v data:" + bytesToHexString(test_buffer)); }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值