Python OpenCV 编写视频而不会在设备崩溃期间丢帧
我有以下用于写入视频文件的基本算法 -
- 创建一个 cv2.VideoWriter() 实例
- 相机在循环中运行
- 检查是否收到开始写入视频的指令,如果是 - 对于每个新图像,执行 write() 命令VideoWriter 实例向视频添加新图像
- 检查是否收到停止写入视频的指令,如果是,则在 VideoWriter 实例上运行 release() 命令以关闭视频文件,并执行一些步骤以准备好写入视频的指令再次收到
启动说明时,这工作得很好并停止视频写入。
然而,在一个测试条件下,运行此代码的设备会物理性地撞到墙上,并且基本上会意外停止工作。显然,在这种情况下,不会收到停止写入视频(来自步骤 4)的指令,并且设备上的最后一个视频始终已损坏。
有什么办法可以防止这种情况发生吗?设备上的视频(尤其是崩溃之前)对于分析崩溃非常重要。
I have the following basic algorithm for writing a video file -
- Create a cv2.VideoWriter() instance
- Camera is running in a loop
- Check if instruction was received to start writing video, if yes - For every new image, perform write() command on the VideoWriter instance to add new image to the video
- Check if instruction was received to stop writing video, if yes - run release() command on the VideoWriter instance to close the video file and perform some steps to be ready in case instruction for writing video is received again
This works perfectly fine when the instructions for starting and stopping the video writing are received.
However, there is a test condition in which the device which is running this code physically crashes into the wall and essentially would stop working unexpectedly. Obviously, in this case the instruction to stop writing video (from step 4) is not received and the last video on the device is always corrupt.
Is there any way to prevent this? The video on the device (especially just before the crash) is quite important for analysis of the crash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论