问题描述
我想即时加密android摄像机捕获的视频.因此,我需要告诉android MediaRecorder
将其视频流写入我的 CipherOutputStream
.问题是 MediaRecorder.setOutputFile()
方法仅接受 FileDescriptor
,并且无法从CipherOutputStream获取加密文件描述符.
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.
所以我的问题是我该如何仿真FileDescriptor来接收数据写入并手动进行加密,或者以某种方式说服 MediaRecorder
将视频流式传输到 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
.
推荐答案
您可以使用LocalServerSocket和LocalSocket来实现所需的内容.
You can use LocalServerSocket and LocalSocket to implement what you want.
LocalServerSocket,它通过LocalServerSocket.getFileDescriptor()提供FileDescriptor
LocalServerSocket which provides the FileDescriptor via LocalServerSocket.getFileDescriptor()
- 启动LocalServerSocket.
- 启动LocalSocket对象并连接到LocalServerSocket.
- 调用LocalServerSocket.accept()以接受来自LocalSocket的连接.
- 建立连接后,可以从LocalServerSocket获取FileDescriptor.
- 可以从LocalSocket.getInputStream()中检索相机写入LocalServerSocket的每个字节,您可以使用for循环获取字节流并写入CipherOutputStream.
请记住将所有步骤都放到新线程中.
Remember to put all steps into a new Thread.
我使用这些API创建了以Camera作为流源的即时流处理器.
I used those APIs to create on-the-fly stream processor with the Camera as stream source.
我希望这会有所帮助.
这篇关于从Android相机即时加密视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!