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 9037007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:08:33+00:00 2026-06-16T09:08:33+00:00

I have a thread that takes screen shots using java.awt.Robot and then encodes them

  • 0

I have a thread that takes screen shots using java.awt.Robot and then encodes them into a video using Xuggler in a loop.
The loop encodes the image, then makes the thread sleep for some time depending upon the frame rate.
All good so far. The problems arise when I try to encode audio.

Specifically, maintaining the sample rate and size

I am using TargetDataLine to read data into a byte[]. This data is already BigEndian formatted.
The magic is in providing proper amount of data at proper time.
My AudioFormat looks like this:

  • Sample Rate: 44000Hz
  • Sample Size In Bits: 16
  • Signed: true
  • BigEndian: true
  • Assuming 10fps and 44000Hz sample rate, I will need to provide

  • what should be the size of the byte[]?
  • how much data? (measured in short because that is what Xuggler wants)
  • and at what time do I call the encodeAudio() method? I mean after 10 passes of the loop or 5 passes, etc.
  • Misc:

    Community member Alex I gave me this formula:

    shortArray.length == ((timeStamp - lastTimeStamp) / 1e+9) * sampleRate * channels;  
    

    a rough calculation got me the answer of 4782 shorts for one second.
    I know when you pass the audio to be encoded it must be for one full second
    So I must capture 480 shorts per pass, and then encode it finally after the 10th pass.
    Please tell me if this deduction is correct?

    • 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-16T09:08:34+00:00Added an answer on June 16, 2026 at 9:08 am

      If you have 16 bits (two bytes) at a sample rate of 44,000 Hz that is 88,000 bytes per second. If you have stereo it is double that. In 1/10 second you need a 1/10th of that. i.e. 8,800 bytes per deci-second (1/10th of a second)

      How do i retrieve short[] from ByteBuffer that has a byte[] as backing array

      byte[] bytes = { };
      ByteBuffer bb = ByteBuffer.wrap(bytes);
      
      short[] shorts = new short[bb.remaining()/2];
      bb.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);
      

      If the order is BigEndian you don’t need to change it.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I have some Java code that takes a screen shot and outputs a png,
    I have a thread that downloads some images from internet using different proxies. Sometimes
    I currently have a thread that I created using CreateRemoteThread(). Everything works great. Upon
    I have a thread in my screen recording application that won't cooperate: package recorder;
    So I have main UI thread and there is a function that takes quite
    I am creating an application that does screen shots of websites using the following
    I have a task that takes about 10 seconds on the UI thread during
    I have a splash screen that i am using it when i am loading
    I have a system that takes Samples. I have multiple client threads in the
    I have a thread that does the following: 1) Do some work 2) Wait

    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.