How to calculate frameSize when encoding?
See original GitHub issueCurrently Encoder requires from us to provide the proper frameSize
parameter:
const opus = new prism.opus.Encoder({ rate: 48000, channels: 1, frameSize: 960 });
I assume ‘requires’ in the TypeScript meaning, as there’s no way to omit it.
There are few concerns.
frame_size is the duration of the frame in samples (per channel).
while prism applies a different meaning to the same thing:
the frame size in bytes to use (e.g. 960 for stereo audio at 48KHz with a frame duration of 20ms)
which I believe brings some confusion.
- And what is more important, is that it’s not clear how to calculate it. Obviously, if it can be calculated automatically then it doesn’t need to be required, does it? If not - then please, explain how to calc it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Video Frame Size Calculator
This video frame size calculator finds the data size of a video frame based on the resolution and color depth.
Read more >How to calculate video size given framerate, resolution and ...
So my calculations were like this: Total Pixels = 1920 * 1080 = 2073600 Size of Each Frame = Total Pixels * 24...
Read more >How to Accurately Calculate Video File Size (Plus - CircleHD
Bitrate = Frame size x Frames Rate. Although the original intent to write about video file size, read along if you would like...
Read more >A Question On How To Calculate Frame Size When Resizing ...
The aim is to just determine height of new image inside MPEG 720x480 matrix representing a 16:9 (or 4:3 in other case) image....
Read more >H.264 Video Frame Size Estimation Edpalm, Viktor - lucris
This is done by isolating the encoder, or an equivalent encoder model, with a series of video sequences which are encoded using varying...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree that the meanings are confusing. The Opus documentation actually offers yet another definition for
frame_size
(seeopus_encode
):This is the definition used by the encoder. For example, a value of 960 for this means that for each distinct Opus packet, each packet is formed from 960 bytes of raw audio.
So with that in mind, it’s sort of annoying, but “frame size” can either be a time duration or a size measurement in bytes.
You can swap between the two fairly easily as long as you have the original sample rate.
For example, for a sample rate of 48000Hz and a frame size of 20ms (=0.02 seconds), the frame size for one channel given in bytes is
48000 * 0.02 = 960
. Therefore, we would need 960 bytes per channel. For stereo audio, a single Opus packet would therefore require960 * 2 = 1920
bytes of audio, 960 for each channel. Note that prism automatically multiplies this number by the number of channels, you don’t need to specify 1920 yourself, 960 will do.While you can derive the frame size in ms from the
TOC
byte of an Opus packet, you can’t derive the sample rate of the audio (as far as I’m aware). This is given by the OpusHead in the audio container. Technically, this can all be inferred by the decoder if it is given the OpusHead along with the Opus packets, however the OpusHead isn’t always easily accessible to the Decoder stream. This might be something I look into for the next version of prism.No problem 😄 Will close now that the issue is resolved.