如果我需要每秒44000字节,每1/10秒需要多少短路(If I need 44000 bytes per second, how many shorts do I need per 1/10th o

编程入门 行业动态 更新时间:2024-10-25 06:28:18
如果我需要每秒44000字节,每1/10秒需要多少短路(If I need 44000 bytes per second, how many shorts do I need per 1/10th of a second)

我有一个线程,使用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 []作为后备数组的ByteBuffer中检索short []

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

如果订单是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)

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.

更多推荐

本文发布于:2023-08-07 20:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字节   shorts   bytes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!