zoukankan      html  css  js  c++  java
  • 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.

    http://blog.sina.com.cn/s/blog_44fa172f0101rg7p.html

  • 相关阅读:
    第二章 Flask——Flask中的request
    第一章 Flask——Flask简介
    第四章 Linux——Nginx环境部署指南
    众测平台
    jmeter进阶
    adb命令对app进行测试
    众测平台
    selenium
    java基础知识
    接口测试工具对比
  • 原文地址:https://www.cnblogs.com/findumars/p/4999085.html
Copyright © 2011-2022 走看看