Encrypt video on the fly from android camera

百般思念 提交于 2021-02-18 11:14:26

问题


I want to encrypt video on the fly that android camera captures. So I need to tell android MediaRecorder to write it video stream to my CipherOutputStream. The problem is MediaRecorder.setOutputFile() method accepts only FileDescriptor and there is no way to get encrypting file descriptor from CipherOutputStream.

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


回答1:


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

LocalServerSocket which provides the FileDescriptor via LocalServerSocket.getFileDescriptor()

  1. Initiate a LocalServerSocket.
  2. Initiate a LocalSocket object and connect to LocalServerSocket.
  3. Invoke LocalServerSocket.accept() to accept connection from LocalSocket.
  4. When the connection established, you can get FileDescriptor from LocalServerSocket.
  5. Every bytes the Camera writes to LocalServerSocket could be retrieved from LocalSocket.getInputStream(), you can use a for-loop to get byte stream and write to CipherOutputStream.

Remember to put all steps into a new Thread.

I used those APIs to create on-the-fly stream processor with the Camera as stream source.

I hope this helps.



来源:https://stackoverflow.com/questions/11638463/encrypt-video-on-the-fly-from-android-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!