안드로이드에서 카메라 프레임에 대해 OpenGL 처리를 수행하고 카메라 미리보기에서 해당 프레임을 표시 한 다음 프레임을 비디오 파일로 인코딩하려고합니다. OpenGL을 사용하여 GLSurfaceView 및 GLSurfaceView.Renderer를 사용하고 비디오 인코딩을 위해 FFMPEG를 사용하여이 작업을 수행하려고합니다.안드로이드에서 Pixel Buffer Objects (PBO) 사용하기
쉐이더를 사용하여 이미지 프레임을 성공적으로 처리했습니다. 이제 처리 된 프레임을 비디오로 인코딩해야합니다. GLSurfaceView.Renderer는 onDrawFrame (GL10 ..) 메소드를 제공합니다. 이 메소드에서는 glReadPixels()를 사용하여 이미지 프레임을 읽은 다음 프레임을 비디오 인코딩으로 큐에 배치하려고합니다. 자체적으로 glReadPixels()가 너무 느려서 - 프레임 속도가 한 자리 숫자입니다. Pixel Buffer Objects를 사용하여 속도를 높이려고합니다. 이것은 작동하지 않습니다. pbo를 연결하면 프레임 속도가 변경되지 않습니다. OpenGL을 처음 사용하는 것이므로 문제를 어디서부터 시작해야할지 모르겠습니다. 이 일을 제대로하고 있습니까? 아무도 내게 어떤 방향을 줄 수 있습니까? 미리 감사드립니다.
public class MainRenderer implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener {
.
.
public void onDrawFrame (GL10 gl10) {
//Create a buffer to hold the image frame
ByteBuffer byte_buffer = ByteBuffer.allocateDirect(this.width * this.height * 4);
byte_buffer.order(ByteOrder.nativeOrder());
//Generate a pointer to the frame buffers
IntBuffer image_buffers = IntBuffer.allocate(1);
GLES20.glGenBuffers(1, image_buffers);
//Create the buffer
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, image_buffers.get(0));
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, byte_buffer.limit(), byte_buffer, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, image_buffers.get(0));
//Read the pixel data into the buffer
gl10.glReadPixels(0, 0, this.width, this.height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, byte_buffer);
//encode the frame to video
enQueueForEncoding(byte_buffer);
//unbind the buffer
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
.
.
}
Google Grafika 예제를 확인하셨습니까? OpenGL 구현이 Android에서 도달 할 수있는 최적의 상태에 가까워지면 너무 놀라지 않을 것입니다. 즉, https://github.com/google/grafika/blob/master/src/com/android/grafika/RecordFBOActivity.java – harism
glReadPixels 호출의 경우 glReadPixels (0, 0, width, height, format, GL_UNSIGNED_BYTE, 0); 마지막에 0이 전달되지만 java가 null을 허용하지 않으므로 JNI를 통해이 작업을 수행해야합니다. 평소처럼 맵 버퍼를 사용합니다. –