delphi - FMX Delphi 10.2 网络摄像头访问冲突,但只是有时
问题描述
谁能帮我这个?我在 Delphi 10.2 中使用 FireMonkey 制作了一个应用程序,它在我的表单上显示来自网络摄像头的视频,并在一个操作中将其插入数据库。网络摄像头的代码是这样的:
https://www.youtube.com/watch?v=EDgCyE0MSVo
我使用TVideoCaptureDevice
类和这段代码:
VideoCamera := TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
if VideoCamera <> nil then
begin
VideoCamera.OnSampleBufferReady := SampleBufferReady;
VideoCamera.StartCapture;
end
else
begin
// MessageDlg('.', TMsgDlgType.mtWarning, [TMsgDlgBtn.mbOK], 0);
end;
在SampleBufferReady()
过程中,我有这行代码:
VideoCamera.SampleBufferToBitmap(frame, true);
当我关闭应用程序时,我有以下代码:
if VideoCamera <> nil then
VideoCamera.StopCapture;
应用程序可以正常工作数千次,但有时我会遇到访问冲突,我想在FMX.Media
或 中的某个地方System
,如您所见:
或者这个
我怎样才能弄清楚会发生什么?
如下所示,我无法更改帧速率
当我列出 AvailableCaptureSettings 时,我只得到 30 fps
现在我与调试器完全不同的打印屏幕
正如你所说,我做了一个新的简单项目。这是完整的代码:
unit Unit3;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Media,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects, FMX.Layouts;
type
TForm3 = class(TForm)
layCamera1: TLayout;
imgCamera1: TImage;
Rectangle1: TRectangle;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
VideoCamera : TVideoCaptureDevice;
procedure SampleBufferSync;
procedure SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
end;
var
Form3: TForm3;
frame: TBitmap;
implementation
{$R *.fmx}
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if VideoCamera <> nil then
VideoCamera.StopCapture;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
VideoCamera:= TCaptureDeviceManager.Current.DefaultVideoCaptureDevice;
if VideoCamera <> nil then
begin
VideoCamera.OnSampleBufferReady := SampleBufferReady;
VideoCamera.StartCapture;
end
else
begin
end;
end;
procedure TForm3.SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
begin
if frame = nil then
frame := TBitmap.Create;
VideoCamera.SampleBufferToBitmap(frame, true);
imgCamera1.Bitmap.Assign(frame);
end;
procedure TForm3.SampleBufferSync;
begin
try
if frame = nil then
frame := TBitmap.Create;
VideoCamera.SampleBufferToBitmap(frame, true);
imgCamera1.Bitmap.Assign(frame);
except on E:Exception do
begin
MessageDlg(E.Message, TMsgDlgType.mtWarning, [TMsgDlgBtn.mbOK], 0);
end;
end;
end;
end.
当我启动程序时,它工作了一段时间,但在这个调试窗口几分钟后意外崩溃(有时是 2 分钟,有时是 22 分钟)
另一个问题是,有时,当我关闭一个程序时,它不会关闭,直到我按下 Delphi 中的停止按钮强制它
解决方案
如评论中所述,我已经构建了 OP 在他的问题中发布的“简单新项目”。
它运行了6个多小时没有任何问题,并且在我做其他事情时仍在运行。我有一个罗技 C310 网络摄像头。安装了所有更新的 Windows 10 Pro 20H2 版本 19042.685。Delphi 10.4.1 更新 1,版本 27.0.38860.1461。
我的结论是 OP 正在使用的 Delphi 10.2 中有一个错误。至少在我正在使用的 Delphi 10.4.1 中,该错误已得到修复。
推荐阅读
- autohotkey - 如何在 AutoHotKey 中从 DDL 制作菜单下拉菜单
- swift - “VisionFace”类型的值没有成员“轮廓”快速错误
- android - 如何使用改造后参数&body,但我不能一起使用@Filed(FormUrlEncoded)&@Body。我能做些什么?
- math - 这个加法总是会产生一个唯一的数字吗?
- python - 带有排列和重复的正则表达式
- ffmpeg - 使用 FFMPEG 在一个基础图像上叠加多个图像
- java - 使用数组或字符更有效吗?
- git - 如何成功将 odoo 11 应用程序迁移到 odoo 12?
- java - 使用 Ant 构建在 xml 中替换值/版本/日期的占位符
- r - R rgl text3d() 工件块对象并更改绘图范围