cats-oss / android-gpuimage

Android filters based on OpenGL (idea from GPUImage for iOS)
9k stars 2.27k forks source link

Camera preview really slow #40

Open okaa-pi opened 11 years ago

okaa-pi commented 11 years ago

Hi! I'm currently trying to port my iPhone app which use GPUImage, on Android. I successfully created a GLSurfaceView and can affect it to my GPUImage object. But the activity is really slow and the preview is laggy.

Is it 'normal'?

Here is my code if it can be helpful:

mCamera = getCameraInstance(); // Method found in the developer guide
if(mCamera == null) { Toast.makeText(this, "No camera found", Toast.LENGTH_SHORT).show(); onBackPressed(); }
mGPUImage = new GPUImage(this); mGPUImage.setGLSurfaceView(surfaceView); mGPUImage.setUpCamera(mCamera, 90, false, frontCAM); mGPUImage.setScaleType(GPUImage.ScaleType.CENTER_CROP);

pboos commented 11 years ago

Yes, this is a currently known problem. One way to speed it up is to lower the resolution of the camera. I have not yet had enough time to get this working well. But I am not using the camera preview anyway, which is why I did not spend much time on it. But if anyone can get it to run faster, please send a pull request.

okaa-pi commented 11 years ago

Thanks for your answer. I faced some other missing elements, so I just used something else. Have a good day.

ubuntudroid commented 11 years ago

@okaa-pi may I ask what other library you ended up using? I also need fast live previews.

ubuntudroid commented 11 years ago

I've traced down slow camera previews to constant GC activity. The root seems to be the data byte array in GPUImageRenderer.onPreviewFrame(). However, as of now I've no solution to that problem. Will investigate further...

ubuntudroid commented 11 years ago

Okay, the issue seems to be related to this bug: http://code.google.com/p/android/issues/detail?id=2794. I've fixed it - preparing a pull request now. However, frame rate doesn't seem to have improved considerably, but at least the constant GC runs are gone.

okaa-pi commented 11 years ago

I just used the standard way of displaying the camera. I realised I didn't need GPUImage to do what I was looking for. Sorry, I can't help you =/

pboos commented 11 years ago

Thank you very much. The GC runs seem to be gone with this, but somehow on my Galaxy Nexus the frame rate drops. That is why i have not merged it in yet. I kind of want to, but not if the frame late goes lower. Or maybe it is just my phone (running CyanogenMod)?

ubuntudroid commented 11 years ago

Let's just continue the discussion over at the pull request's thread: https://github.com/CyberAgent/android-gpuimage/pull/44#issuecomment-20457410

jibinjoseph commented 8 years ago

Any solution for this issue ? me too facing this issue ? Any help please ?

jibinjoseph commented 8 years ago

use Camera.set preview size method and set a lower res value eg(640,480)