Delphi XE6 Android视频采集


本文整理自网络,侵删。

 FMX支持视频采集,具体见FMX.Media,提供了很类支持音频、视频的处理。
按帮助文档,用Note3做了测试,结果,效率太低,不可用。
具体可查询帮助Video Capturing一节,我就是按这个把代码复制过来做的测试.
一点进展:
对于这么低的效率,经与朋友讨论,应该是FMX完全自己处理的结果,如此说来,如果我们能调用Android内置的相机进行录像,然后取得录像文件,该问题就解决了。这样想来,Delphi XE6支持的拍照功能,就是按这个原理实现的,非常适用了!为此,XE6带做一个Standard Action,叫TTakePhotoFromCameraAction,非常快捷的支持拍照的开发,如果再提供一个TTakeVideoFromCameraAction该有多好!可惜了,现在还没有。
为了调用内置相机,朋友提醒我说,就是调用Android的Intent,怎么调用,还不会,那有没有人基于Android开发这样的控件呢?还真查到一组控件:DPF component suite for Android, 只可惜,目前还没有提供录像功能。
附测试的FMX代码:
unit Unit2;
interface
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
  FMX.StdCtrls, FMX.Objects, FMX.ListBox,FMX.Media;
type
  TForm2 = class(TForm)
    Layout1: TLayout;
    StartButton: TButton;
    ComboBox1: TComboBox;
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure StartButtonClick(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    VideoCamera: TVideoCaptureDevice;
    procedure SampleBufferSync;
    procedure SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
  end;
var
  Form2: TForm2;
implementation
{$R *.fmx}
{ TForm2 }
procedure TForm2.ComboBox1Change(Sender: TObject);
begin
  VideoCamera := TVideoCaptureDevice
    //(TCaptureDeviceManager.Current.GetDevicesByName(ComboBox1.Selected.Text));
    (TCaptureDeviceManager.Current.Devices[1]);
  if (VideoCamera <> nil) then
  begin
    StartButton.Enabled := true;
  end;
end;
procedure TForm2.FormCreate(Sender: TObject);
var
  DeviceList: TCaptureDeviceList;
  i: integer;
begin
  DeviceList := TCaptureDeviceManager.Current.GetDevicesByMediaType
    (TMediaType.Video);
  for i := 0 to DeviceList.Count - 1 do
  begin
    ComboBox1.Items.Add(DeviceList[i].Name);//这里在note3上取不到Name.
  end;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
  if VideoCamera <> nil then
    VideoCamera.StopCapture;
end;
procedure TForm2.SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
begin
  TThread.Synchronize(TThread.CurrentThread, SampleBufferSync);
  //Resize the image so that the video is buffered in its original size
//  Image1.Width:=Image1.Bitmap.Width;
//  Image1.Height:=Image1.Bitmap.Height;
end;
procedure TForm2.SampleBufferSync;
begin
  VideoCamera.SampleBufferToBitmap(Image1.Bitmap, true);
end;
procedure TForm2.StartButtonClick(Sender: TObject);
begin
  if (VideoCamera <> nil) then
  begin
    if (VideoCamera.State = TCaptureDeviceState.Stopped) then
    begin
      VideoCamera.OnSampleBufferReady := SampleBufferReady;
      VideoCamera.StartCapture;
      StartButton.Text := 'Stop';
    end
    else
    begin
      VideoCamera.StopCapture;
      StartButton.Text := 'Start';
    end;
  end
  else
  begin
    Caption := 'Video capture devices not available.';
  end;
end;
end.

相关阅读 >>

Delphi 随鼠标移动的十字线的快速画法

Delphi query1 导出csv txt

Delphi int64 与 currency

Delphi 将 html 代码直接加入到 twebbrowser 组件中去

Delphi的字符串与16进制的相互转换函数的汇编代码

Delphi 在firemonkey应用程序中设置application.title

Delphi memo1删除前n行

Delphi 通用压缩单元

Delphi shellexecute openurl 的跨平台实现

Delphi 如何解析网址?

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...