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

  • Home
  • SEARCH
  • 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 7877339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:20:35+00:00 2026-06-03T03:20:35+00:00

I am currently developing an application that needs to record audio, encode it as

  • 0

I am currently developing an application that needs to record audio, encode it as AAC, stream it, and do the same in reverse – receiving stream, decoding AAC and playing audio.

I successfully recorded AAC (wrapped in a MP4 container) using the MediaRecorder, and successfully up-streamed audio using the AudioRecord class. But, I need to be able to encode the audio as I stream it, but none of these classes seem to help me do that.

I researched a bit, and found that most people that have this problem end up using a native library like ffmpeg.

But I was wondering, since Android already includes StageFright, that has native code that can do encoding and decoding (for example, AAC encoding and AAC decoding), is there a way to use this native code on my application? How can I do that?

It would be great if I only needed to implement some JNI classes with their native code. Plus, since it is an Android library, it would be no licensing problems whatever (correct me if I’m wrong).

  • 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-03T03:20:36+00:00Added an answer on June 3, 2026 at 3:20 am

    yes, you can use libstagefright, it’s very powerful.

    Since stagefright is not exposed to NDK, so you will have to do extra work.

    There are two ways:

    (1) build your project using android full source tree. This way takes a few days to setup, once ready, it’s very easy, and you can take full advantage of stagefright.

    (2) you can just copy include file to your project, it’s inside this folder:

    android-4.0.4_r1.1/frameworks/base/include/media/stagefright

    then you will have export the library function by dynamically loading libstagefright.so, and you can link with your jni project.

    To encode/decode using statgefright, it’s very straightforward, a few hundred of lines can will do.

    I used stagefright to capture screenshots to create a video, which will be available in our Android VNC server, to be released soon.

    the following is a snippet, I think it’s better than using ffmpeg to encode a movie. You can add audio source as well.

    class ImageSource : public MediaSource {
       ImageSource(int width, int height, int colorFormat)
        : mWidth(width),
          mHeight(height),
          mColorFormat(colorFormat)
       {
       }
    
       virtual status_t read(
            MediaBuffer **buffer, const MediaSource::ReadOptions *options) {
           // here you can fill the buffer with your pixels
       }
    
       ...
    };
    
    int width = 720;
    int height = 480;
    sp<MediaSource> img_source = new ImageSource(width, height, colorFormat);
    
    sp<MetaData> enc_meta = new MetaData;
    // enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
    // enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
    enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
    enc_meta->setInt32(kKeyWidth, width);
    enc_meta->setInt32(kKeyHeight, height);
    enc_meta->setInt32(kKeySampleRate, kFramerate);
    enc_meta->setInt32(kKeyBitRate, kVideoBitRate);
    enc_meta->setInt32(kKeyStride, width);
    enc_meta->setInt32(kKeySliceHeight, height);
    enc_meta->setInt32(kKeyIFramesInterval, kIFramesIntervalSec);
    enc_meta->setInt32(kKeyColorFormat, colorFormat);
    
    sp<MediaSource> encoder =
        OMXCodec::Create(
                client.interface(), enc_meta, true, image_source);
    
    sp<MPEG4Writer> writer = new MPEG4Writer("/sdcard/screenshot.mp4");
    writer->addSource(encoder);
    
    // you can add an audio source here if you want to encode audio as well
    // 
    //sp<MediaSource> audioEncoder =
    //    OMXCodec::Create(client.interface(), encMetaAudio, true, audioSource);
    //writer->addSource(audioEncoder);
    
    writer->setMaxFileDuration(kDurationUs);
    CHECK_EQ(OK, writer->start());
    while (!writer->reachedEOS()) {
        fprintf(stderr, ".");
        usleep(100000);
    }
    err = writer->stop();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently developing an application that needs to store a 10 to 20 digit
I am currently developing an application that needs to decode a UDP multicast RTSP
I'm currently developing an application that needs to parse some (a big file of)
I'm currently developing an application that needs to communicate with a webservice on the
I'm currently developing a MVC3 web application that needs to require extranet users to
I'm currently developing an application that needs to store data in it's on database,
I am currently developing an iOS application that needs a backend to pull data
I'm currently developing a C-module for a Java-application that needs some performance improvements (see
I am currently developing an Android 2.2 application that needs to resume to the
In the small application that I'm currently developing for a customer I need to

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.