无尽的视频录制
我正在构建一个应用程序,它将保存 60 秒的录制视频缓冲区。视频录制需要运行较长时间(24-48 小时)。我的录制似乎没有任何问题,但几个小时后我似乎与 Camera
或 Surface
失去了连接。
我正在设置最大持续时间:MediaRecorder.setMaxDuration(10 * 1000)
,以便录制分为 10 秒的片段。
每次重新开始录制时,我都会以重复使用 6 个文件的方式递增输出文件。目的是始终保留 60 秒的历史记录。
如果我在 1-2 小时后停止录制,视频可以正常播放。但是,如果我让它运行 3-4 个多小时并停止录制,视频将仅显示黑色输出和音频。换句话说,就好像它失去了与摄像头或 Surface 的连接但仍在继续录制音频。
谁能解释这种行为?
如果不出意外,是否有更好的方法来录制X秒的视频片段?
仅供参考:我正在使用唤醒锁,以便屏幕/CPU 保持打开状态。
I am building an app that will hold a 60 second buffer of recorded video. The video recording needs to run for an extended period of time (24-48 hours). I do not seem to have any issues with recording, but it appears that I lose the connection with my Camera
or Surface
after a few hours of time.
I am setting the max duration: MediaRecorder.setMaxDuration(10 * 1000)
so that recording is broken up into 10 second segments.
Each time I restart my recording I am incrementing the output file in such a way that 6 files are reused. The purpose is to keep a 60 second history at all times.
If I stop the recording after 1-2 hours the videos play back fine. However, if I let it run for 3-4+ hours and stop the recording, the videos shows only black output with audio. In other words, it is as if it lost a connection with the camera or surface but continued recording audio.
Can anyone explain this behavior?
If nothing else, is there a better way to record X second segments of video?
FYI: I am using a wake lock so that the screen/CPU stay on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里已经回答了我自己的问题。我没有太多信息,但希望这能提供足够的信息来帮助处于类似困境的其他人。
首先,我从未发布过我的代码,因为它太长了。我没有发布我的代码片段,因为我不知道问题出在哪里。尽管我现在可以正常工作,但我仍然不知道我的旧代码出了什么问题。
我的建议:
我最终废弃了我的代码并从开发 API 演示中找到的代码重新开始:
CameraPreview
- 我在该网站上的至少一个线程中找到了此引用。之后我就可以毫无问题地连续录制几个小时。因此,如果您遇到类似的情况,我建议使用
CameraPreview
代码作为起点。I have sort of answered my own question here. I don't have a lot of information, but hopefully this will provide enough information to help others in a similar predicament.
First, I never posted my code because it's way too lengthy. I didn't post snippets of my code because I did not know where the problem was originating. Despite the fact that I have this working now, I still do not know what was wrong with my old code.
My suggestion:
I ended up scrapping my code and starting fresh with the code found in the Development API Demos:
CameraPreview
-- I found this references in at least one thread on this site.After that I was able to continually record for hours on end without problem. So if you are in a similar situation, I would suggest using the
CameraPreview
code as a starting point.