I hope this question will be interpreted more as the nature of maths than the coding examples provided within:
Using the ffmpeg-fluent
library for Node.js I'm able to extract PCM (WAV) audio. I've enabled the .native() capability to the chain of commands for ffmpeg which, for both video and audio, transcodes the input data at the same rate as the FPS of the video feed, 20.
I want to find out the amount of bytes that is contained within a "frame" of audio, correlating it to a frame of video data.
My script delivers me a chunk size of 4096
bytes.
Trying to calculate this ahead of time has been problematic for me since I thought the formula was:
48.000 / 20 * samplesize
By the logic that samples per second / frames per second * size of a sample
would give me the size in bytes at each frame however the math does not add up.
Attached below you'll find the WAV header of the audio stream extracted using a hex dump:
Offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 52 49 46 46 FF FF FF FF 57 41 56 45 66 6D 74 20 RIFFÿÿÿÿWAVEfmt
00000010 10 00 00 00 01 00 02 00 80 BB 00 00 00 EE 02 00 ........»...î..
00000020 04 00 10 00 4C 49 53 54 1A 00 00 00 49 4E 46 4F ....LIST....INFO
00000030 49 53 46 54 0E 00 00 00 4C 61 76 66 35 38 2E 32 ISFT....Lavf58.2
00000040 39 2E 31 30 30 00 64 61 74 61 FF FF FF FF 9.100.dataÿÿÿÿ
When parsing this with node.js I confirm that my block align is 4 bytes and sample rate is 48000, using offsets from the WAV header documentation found at: http://soundfile.sapp.org/doc/WaveFormat/
console.log(chunk.slice(24, 28).readUInt32LE()); // Sample rate.
console.log(chunk.slice(32, 34).readUInt16LE()); // Block Align.
console.log(chunk.slice(34, 36).readUInt16LE()); // Bits per sample.
48000
4
16
Note: In case I screwed something up with the commands in ffmpeg-fluent by combining native processing with a new FPS, the original FPS of the input signal is 25fps.