Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:14:09+00:00 2026-06-05T18:14:09+00:00

I’m working on a little Android app to stream some camera footage (as a

  • 0

I’m working on a little Android app to stream some camera footage (as a series of JPEGs) to my computer. With no processing, the frame buffer receives camera preview images at about 18 fps. When I add in

YuvImage yuv = new YuvImage(data, ImageFormat.NV21, dimensions.width, dimensions.height, null);
yuv.compressToJpeg(new Rect(0, 0, dimensions.width, dimensions.height), 40, out);

the frame rate drops to about 7 fps. So I thought I’d write my own JPEG encoder in C and speed it up a bit. Well I was in for a surprise. I’m now getting 0.4 fps!

So now I need to profile and optimize my C code, but I don’t really know where to begin. I’m using these GCC flags:

-Wall -std=c99 -ffast-math -O3 -funroll-loops

Is there anything I can improve there?

Other than that, my JPEG encoder is just a straight forward implementation. Write header info, write quantization and Huffman tables, then entropy encode the data. The DCT is using AA&N’s method I believe is the fastest way of doing this.

Perhaps there is a problem with the JNI overhead?

I’m allocating the memory in Java using:

frame_buffer = ByteBuffer.allocate(raw_preview_buffer_size).array();
jpeg_buffer = ByteBuffer.allocate(10000000).array();

and then pulling it in with this code (pardon the spaghetti at the moment):

void Java_com_nechtan_limelight_activities_CameraPreview_handleFrame(JNIEnv* env, jobject this, jbyteArray nv21data, jbyteArray jpeg_buffer) {
    jboolean isCopyNV21;
    jboolean isCopyJPEG;
    int jpeg_size = 0;

    jbyte* nv21databytes = (*env)->GetByteArrayElements(env, nv21data, &isCopyNV21);
    jbyte* jpeg_buffer_bytes = (*env)->GetByteArrayElements(env, jpeg_buffer, &isCopyJPEG);

    if (nv21databytes != NULL) {
        if (jpeg_buffer_bytes != NULL) {
            jpeg_size = compressToJpeg((UCHAR*) nv21databytes, (UCHAR*) jpeg_buffer_bytes, 640, 480);
            (*env)->ReleaseByteArrayElements(env, jpeg_buffer, jpeg_buffer_bytes, 0);
            (*env)->ReleaseByteArrayElements(env, nv21data, nv21databytes, JNI_ABORT);
            }
        else {
            __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "JPEG data null!");
            }
        }
    else {
        __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NV21 data null!");
        }

    }

Am I doing something inefficient here? What is a good way to profile JNI code?

Other than those things, the only thing I can think of is that I’m going to have to read about NEON and vectorize this stuff. Ugh…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:14:11+00:00Added an answer on June 5, 2026 at 6:14 pm

    Try using the build in encoder:

     private byte[] compressYuvToJpeg(final byte[] yuvData) {
        mJpegCompressionBuffer.reset();
        YuvImage yuvImage =
            new YuvImage(yuvData, ImageFormat.NV21, mPreviewWidth, mPreviewHeight, null);
        yuvImage.compressToJpeg(new Rect(0, 0, mPreviewWidth, mPreviewHeight), mJpegQuality,
            mJpegCompressionBuffer);
        return mJpegCompressionBuffer.toByteArray();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to construct a data frame in an Rcpp function, but when I
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.