jean343 / Node-OpenMAX

Node wrapper for the OpenMAX library
https://www.npmjs.com/package/openmax
MIT License
16 stars 5 forks source link

Adding CameraEncode example #8

Closed sledesm closed 6 years ago

sledesm commented 6 years ago

This is a simple example to use the ImageEncode component to convert live video into a stream of jpeg files. The purpose is to use this data flow to create a set of jpeg images to push to a browser using websockets.

However, the size that I get in the socket is all the time the same, regardless of the actual jpeg size, and I do not know how to find out the actual buffer length.

sledesm commented 6 years ago

I have here a proposed solution for the length problem:

  readDone(outputBuffer) {
    var buffer: Buffer = outputBuffer.buf;

    // Catch EOF
    if (outputBuffer.header.nFlags & 0x00000001/*BUFFERFLAG_EOS*/) {
      this.info("Received BUFFERFLAG_EOS");
      if (this.autoClose) {
        this.close();
      }
      return;
    } else {
      buffer.onBufferDone = () => {
        this.fillBuffer(outputBuffer.header);
      };
    // ADDING THE ACTUAL USED LENGTH IN THE BUFFER!!
      buffer.usedLength = outputBuffer.header.nFilledLen;
    }
    this.push(buffer);
  }

I added the property buffer.usedLength so that I can use the part of the buffer which is actually used.

sledesm commented 6 years ago

Updated cameraEncode example: sample output

Received compressed frame with length:  81920  but used:  66985
Received compressed frame with length:  81920  but used:  66798
Received compressed frame with length:  81920  but used:  66920
Received compressed frame with length:  81920  but used:  66913
Received compressed frame with length:  81920  but used:  67026
Received compressed frame with length:  81920  but used:  66885
Received compressed frame with length:  81920  but used:  66949
Received compressed frame with length:  81920  but used:  67040
Received compressed frame with length:  81920  but used:  67073
Received compressed frame with length:  81920  but used:  67070
Received compressed frame with length:  81920  but used:  67066
Received compressed frame with length:  81920  but used:  66995
Received compressed frame with length:  81920  but used:  66932
Received compressed frame with length:  81920  but used:  66987
Received compressed frame with length:  81920  but used:  67140
Received compressed frame with length:  81920  but used:  67131
Received compressed frame with length:  81920  but used:  67149
Received compressed frame with length:  81920  but used:  67048
Done
jean343 commented 6 years ago

Cool, I am thinking to write some code to write the files to the disk for sample purpose.