博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
视频采集,存成avi
阅读量:5254 次
发布时间:2019-06-14

本文共 2911 字,大约阅读时间需要 9 分钟。

视频采集,存成avi

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
   Dialogs, ExtCtrls, StdCtrls;

type

  TForm1 = class(TForm)
    Panel1: TPanel;
    OpenVideo: TButton;
    CloseVideo: TButton;
    GrabFrame: TButton;
    SaveBMP: TButton;
    StartAVI: TButton;
    StopAVI: TButton;
    SaveDialog1: TSaveDialog;
    procedure FormCreate(Sender: TObject);
    procedure OpenVideoClick(Sender: TObject);
    procedure CloseVideoClick(Sender: TObject);
    procedure GrabFrameClick(Sender: TObject);
    procedure SaveBMPClick(Sender: TObject);
    procedure StartAVIClick(Sender: TObject);
    procedure StopAVIClick(Sender: TObject);
  private
    { Private declarations }
    hWndC : THandle;
    CapturingAVI : bool;
  public
    { Public declarations }
  end;

var

  Form1: TForm1;

implementation

{$R *.DFM}

const WM_CAP_START                  = WM_USER;

const WM_CAP_STOP                   = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT         = WM_CAP_START + 10;
const WM_CAP_DRIVER_DISCONNECT      = WM_CAP_START + 11;
const WM_CAP_SAVEDIB                = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME             = WM_CAP_START + 60;
const WM_CAP_SEQUENCE               = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START +  20;

function capCreateCaptureWindowA(lpszWindowName : PCHAR;

                                 dwStyle : longint;
                                 x : integer;
                                 y : integer;
                                 nWidth : integer;
                                 nHeight : integer;
                                 ParentWin  : HWND;
                                 nId : integer): HWND;
                                 STDCALL EXTERNAL 'AVICAP32.DLL';

procedure TForm1.FormCreate(Sender: TObject);

begin
  CapturingAVI := false;
  hWndC := 0;
  SaveDialog1.Options :=
    [ofHideReadOnly, ofNoChangeDir, ofPathMustExist]
end;

procedure TForm1.OpenVideoClick(Sender: TObject);

begin
  hWndC := capCreateCaptureWindowA('My Own Capture Window',
                                   WS_CHILD or WS_VISIBLE ,
                                   Panel1.Left,
                                   Panel1.Top,
                                   Panel1.Width,
                                   Panel1.Height,
                                   Form1.Handle,
                                   0);
  if hWndC <> 0 then
    SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
end;

procedure TForm1.CloseVideoClick(Sender: TObject);

begin
  if hWndC <> 0 then begin
    SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
   hWndC := 0;
   end;
end;

procedure TForm1.GrabFrameClick(Sender: TObject);

begin
  if hWndC <> 0 then
    SendMessage(hWndC, WM_CAP_GRAB_FRAME, 0, 0);
end;

procedure TForm1.SaveBMPClick(Sender: TObject);

begin
  if hWndC <> 0 then begin
    SaveDialog1.DefaultExt := 'bmp';
    SaveDialog1.Filter := 'Bitmap files (*.bmp)|*.bmp';
    if SaveDialog1.Execute then
      SendMessage(hWndC,
                  WM_CAP_SAVEDIB,
                  0,
                  longint(pchar(SaveDialog1.FileName)));
  end;
end;

procedure TForm1.StartAVIClick(Sender: TObject);

begin
  if hWndC <> 0 then begin
    SaveDialog1.DefaultExt := 'avi';
    SaveDialog1.Filter := 'AVI files (*.avi)|*.avi';
    if SaveDialog1.Execute then begin
       CapturingAVI := true;
       SendMessage(hWndC,
                   WM_CAP_FILE_SET_CAPTURE_FILEA,
                   0,
                   Longint(pchar(SaveDialog1.FileName)));
       SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
    end;
  end;
end;

procedure TForm1.StopAVIClick(Sender: TObject);

begin
  if hWndC <> 0 then begin
    SendMessage(hWndC, WM_CAP_STOP, 0, 0);
    CapturingAVI := false;
  end;
end;

end.

转载于:https://www.cnblogs.com/yzryc/p/6374432.html

你可能感兴趣的文章
51nod1076 (边双连通)
查看>>
Item 9: Avoid Conversion Operators in Your APIs(Effective C#)
查看>>
深入浅出JavaScript(2)—ECMAScript
查看>>
STEP2——《数据分析:企业的贤内助》重点摘要笔记(六)——数据描述
查看>>
ViewPager的onPageChangeListener里面的一些方法参数:
查看>>
Jenkins关闭、重启,Jenkins服务的启动、停止方法。
查看>>
CF E2 - Array and Segments (Hard version) (线段树)
查看>>
Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
查看>>
SIGPIPE并产生一个信号处理
查看>>
CentOS
查看>>
Linux pipe函数
查看>>
java equals 小记
查看>>
爬虫-通用代码框架
查看>>
2019春 软件工程实践 助教总结
查看>>
YUV 格式的视频呈现
查看>>
Android弹出框的学习
查看>>
现代程序设计 作业1
查看>>
在android开发中添加外挂字体
查看>>
Zerver是一个C#开发的Nginx+PHP+Mysql+memcached+redis绿色集成开发环境
查看>>
多线程实现资源共享的问题学习与总结
查看>>