How to get a higher camera preview like snapchat?

In Android,

Does anyone know what kind of snapchat trick it takes to get such high fps on its camera preview? I tried various methods:

  • using texture representation instead of surface representation
  • hardware acceleration
  • using lower resolutions
  • using various preview formats (YV12, NV21 resets frames)
  • change focus mode

No one left me anywhere near a constant 30 frames per second, or perhaps even higher, which seems to get snapchat. I can just get to the same fps as the google camera app, but it’s not very convenient, and my displays have much lower resolution.

EDIT:

The method used is similar to that used by the official application for recording video on Android. The preview has the same image quality and is locked up to 30 frames per second.

+3
source share
2 answers

I figured they used the Android NDK. You can find more information in the Android developer .

Using pure C / C ++ is faster than JAVA code in such important tasks as image and video processing.

You can also try to improve performance by compiling the application with another compiler, such as the Intel compiler .

+2
source

try this it works

public void takeSnapPhoto() {
camera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {
        Camera.Parameters parameters = camera.getParameters();
        int format = parameters.getPreviewFormat();
        //YUV formats require more conversion
        if (format == ImageFormat.NV21 || format == ImageFormat.YUY2 || format == ImageFormat.NV16) {
            int w = parameters.getPreviewSize().width;
            int h = parameters.getPreviewSize().height;
            // Get the YuV image
            YuvImage yuv_image = new YuvImage(data, format, w, h, null);
            // Convert YuV to Jpeg
            Rect rect = new Rect(0, 0, w, h);
            ByteArrayOutputStream output_stream = new ByteArrayOutputStream();
            yuv_image.compressToJpeg(rect, 100, output_stream);
            byte[] byt = output_stream.toByteArray();
            FileOutputStream outStream = null;
            try {
                // Write to SD Card
                File file = createFileInSDCard(FOLDER_PATH, "Image_"+System.currentTimeMillis()+".jpg");
                //Uri uriSavedImage = Uri.fromFile(file);
                outStream = new FileOutputStream(file);
                outStream.write(byt);
                outStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }
        }
    }
});}
+3
source

All Articles