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:
Assuming 10fps and 44000Hz sample rate, I will need to provide
byte[]?
short because that is what Xuggler wants) 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?
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)
If the order is BigEndian you don’t need to change it.