Android video encryption on the fly

I want to encrypt the video on the fly to capture a camera for Android. So I need to tell MediaRecorder to write the video stream to my CipherOutputStream . The problem is that the MediaRecorder.setOutputFile() method only accepts FileDescriptor , and there is no way to get the file descriptor encryption from CipherOutputStream.

So my question is, how can I either emulate FileDescriptor to receive data records and do encryption manually, or somehow convince MediaRecorder to stream video to CipherOutputStream .

+7
source share
1 answer

You can use LocalServerSocket and LocalSocket to implement what you want.

LocalServerSocket, which provides a FileDescriptor through LocalServerSocket.getFileDescriptor ()

  • Initiate LocalServerSocket.
  • Initiate a LocalSocket object and connect to LocalServerSocket.
  • Call LocalServerSocket.accept () to accept the connection to LocalSocket.
  • When the connection is established, you can get the FileDescriptor from LocalServerSocket.
  • Each byte that the camera writes to LocalServerSocket can be obtained from LocalSocket.getInputStream (), you can use the for-loop to get the byte stream and write to CipherOutputStream.

Remember to put all the steps in a new thread.

I used these APIs to create a stream processor with a stream as a stream source.

Hope this helps.

+4
source

All Articles