I'm attempting to create RTP packets for an MJPEG video. First, I read the first 5 bytes of the file which gives me the length of the frame, and then I read the returned size.
Here is my code:
while(totalSizeScanned < totalSize){
var tmp_buf = Buffer(5)
fs.readSync(fd,tmp_buf,totalSizeScanned,5);
totalSizeScanned += 5;
var stringBuffer = tmp_buf.toString("utf-8");
this.total_len = parseInt(stringBuffer, 10);
var frame_buf = Buffer(this.total_len);
fs.readSync(fd, frame_buf, totalSizeScanned, this.total_len);
file_content[frameNo] = frame_buf;
frameNo++;
totalSizeScanned += this.total_len;
}
This is giving me a "Length extends beyond buffer" error on the second readSync call. I don't understand why this is happening, as the size I read should be the size of the buffer. I've been searching the docs and google for about an hour but haven't been able to find anything. I'm new to Node so this may be trivial but I'm not sure.
Thanks.
Take out the bytes for the length, start at 0 in the new buffer and add in null for position
fs.readSync(fd, frame_buf, 0, this.total_len-5,null);