我有一个线程,使用java.awt.Robot拍摄屏幕截图,然后在循环中使用Xuggler将它们编码为视频。 循环对图像进行编码,然后根据帧速率使线程休眠一段时间。 到目前为止都很好。 当我尝试编码音频时会出现问题。
具体来说,保持采样率和大小
我正在使用TargetDataLine将数据读入byte[] 。 此数据已经格式化为BigEndian 。 神奇的是在适当的时候提供适当数量的数据。 我的AudioFormat看起来像这样:
采样率:44000Hz 比特样本大小:16 签名:是的 BigEndian:是的 假设采样速率为10fps和44000Hz,我需要提供 什么应该是byte[]的大小? 多少数据? ( short因为这是Xuggler想要的) 我什么时候调用encodeAudio()方法? 我的意思是经过10次循环或5次传球等。其他:
社区成员Alex我给了我这个公式:
shortArray.length == ((timeStamp - lastTimeStamp) / 1e+9) * sampleRate * channels;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?
最满意答案
如果你有44位的采样率16位(两个字节),即每秒88,000字节。 如果你有立体声,那就是双倍。 在1/10秒内你需要1/10。 即每秒十八万字节(1/10秒)
byte[] bytes = { }; ByteBuffer bb = ByteBuffer.wrap(bytes); short[] shorts = new short[bb.remaining()/2]; bb.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);我如何从具有byte []作为后备数组的ByteBuffer中检索short []
如果订单是BigEndian,则无需更改。
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)
byte[] bytes = { }; ByteBuffer bb = ByteBuffer.wrap(bytes); short[] shorts = new short[bb.remaining()/2]; bb.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);How do i retrieve short[] from ByteBuffer that has a byte[] as backing array
If the order is BigEndian you don't need to change it.
更多推荐
发布评论