⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u_avicapture.pas

📁 一个简单的学籍管理软件
💻 PAS
字号:
unit U_AviCapture;

interface
uses Windows, SysConst, IniFiles, U_AviCap, Math;

const
  MAXVIDDRIVERS = 10;
  CW_USEDEFAULT = integer($80000000);
  DEF_CAPTURE_RATE = 111112;

type
  TDeviceRec = record
    DeviceName, DeviceVersion: string;
    DeviceIndex: integer;
  end;

  TConfigRec = record
    bCenter: boolean;
    bToolBar: boolean;
    bStatusBar: boolean;
    bAutoSizeFrame: boolean;
    iBackColor: integer;

    iWinX: integer;
    iWinY: integer;
    iWinCX: integer;
    iWinCY: integer;
    iWinShow: integer;

    bOverlay: boolean;
    bLive: boolean;
  end;

function RateToMicroSec(Rates: integer): LongInt;
function MicroSecToRate(dwMicroSec: LongInt): integer;

procedure vidcapSetLive(hWndCap: HWND; bLive: boolean);
procedure vidcapSetOverlay(hWndCap: HWnd; bOverlay: boolean);
procedure vidcapSetCaptureFile(hWndCap: HWnd; pFileName: PChar);

function vidcapEnumerateDrivers(Devices: array of TDeviceRec): integer;
function vidcapInitHardware(hwndCap: HWND; uIndex: UINT; var bIsScrnCap: Boolean): boolean;
procedure vidcapReadProfile(var aConfig: TConfigRec);
procedure vidcapWriteProfile(aConfig: TConfigRec);
procedure vidcapReadSettingsProfile(var aCapParms: TCAPTUREPARMS);
procedure vidcapWriteSettingsProfile(aCapParms: TCAPTUREPARMS);

implementation

function RateToMicroSec(Rates: integer): LongInt;
begin
  if (Rates < 1) then
    Result := 0
  else
    Result := Trunc(1000000 / Rates + 0.5);
end;

function MicroSecToRate(dwMicroSec: LongInt): integer;
begin
  if dwMicroSec = 0 then
    Result := 0
  else
    Result := Trunc(1000000 / dwMicroSec);
end;

procedure vidcapSetLive(hWndCap: HWND; bLive: boolean);
begin
  capPreview(hWndCap, Word(bLive));
  if bLive then
    vidcapSetOverlay(hWndCap, FALSE);
end;

procedure vidcapSetOverlay(hWndCap: HWnd; bOverlay: boolean);
var
  aCapDriverCaps: TCapDriverCaps;
begin
  capDriverGetCaps(hWndCap, LongInt(@aCapDriverCaps), sizeof(aCapDriverCaps));
  if not aCapDriverCaps.fHasOverlay then
    Exit;

  capOverlay(hWndCap, Word(bOverlay));
  if bOverlay then
    vidcapSetLive(hWndCap, FALSE);
end;

procedure vidcapSetCaptureFile(hWndCap: HWnd; pFileName: PChar);
begin
  capFileSetCaptureFile(hWndCap, LongInt(pFileName));
end;

function vidcapEnumerateDrivers(Devices: array of TDeviceRec): integer;
var
  achDeviceVersion: string;
  achDevice: string;
  uIndex: integer;
begin
  Result := 0;

  for uIndex := 0 to MAXVIDDRIVERS do
  begin
    achDeviceVersion := StringOfChar(' ', 80);
    achDevice := StringOfChar(' ', 80);
    if capGetDriverDescription(uIndex,
      PChar(achDevice), Length(achDevice),
      PChar(achDeviceVersion), Length(achDeviceVersion)) then
    begin
      // Concatenate the device name and version strings
      Devices[uIndex].DeviceName := achDevice;
      Devices[uIndex].DeviceVersion := achDeviceVersion;
      Devices[uIndex].DeviceIndex := uIndex;
      Inc(Result);
    end
    else
    begin
      // Concatenate the device name and version strings
      Devices[uIndex].DeviceName := '';
      Devices[uIndex].DeviceVersion := '';
      Devices[uIndex].DeviceIndex := -1;
    end
  end;
end;

function vidcapInitHardware(hwndCap: HWND; uIndex: UINT; var bIsScrnCap: Boolean): boolean;
var
  bLive, bOverlay: Boolean;
  szName, szVersion: string;
  aCapDriverCaps: TCAPDRIVERCAPS;
  aCapStatus: TCapStatus;
begin
  // Try connecting to the capture driver

  if capDriverConnect(hwndCap, uIndex) <> 0 then
  begin
    Result := True;
    bLive := True;
    bOverlay := True;
  end
  else
  begin
    Result := False;
    bLive := False;
    bOverlay := False;
  end;
  // Get the capabilities of the capture driver
  capDriverGetCaps(hwndCap, Integer(@aCapDriverCaps), sizeof(TCAPDRIVERCAPS));
  // Get the settings for the capture window
  capGetStatus(hwndCap, Integer(@aCapStatus), sizeof(TCapStatus));
  // Unlike all other capture drivers, Scrncap.drv needs to use
  // a Yield callback, and we don't want to abort on mouse clicks,
  // so determine if the current driver is Scrncap.drv
  szName := StringOfChar(' ', MAX_PATH);
  szVersion := StringOfChar(' ', MAX_PATH);
  capGetDriverDescription(uIndex,
    PChar(szName), Length(szName),
    PChar(szVersion), Length(szVersion));

  // Set a flag if we're using Scrncap.drv
  bIsScrnCap := Boolean(Pos('Screen Capture', szName));

  // Get video format and adjust capture window
  //InvalidateRect(hWndMain, nil, TRUE);

  // set the preview rate (units are millisecs)
  if Result then
    capPreviewRate(hwndCap, 30)
  else
    capPreviewRate(hwndCap, 0);

  vidcapSetCaptureFile(hwndCap, 'c:\czy001.avi');
  // set live/overlay to default
  vidcapSetLive(hWndCap, bLive);
  vidcapSetOverlay(hWndCap, bOverlay);
end;

procedure vidcapReadProfile(var aConfig: TConfigRec);

function LimitRange(Val, Low, Hi: integer): integer;
  begin
    Result := Val;
    if Result > Hi then
      Result := Hi;
    if Result < Low then
      Result := Low;
   //max(Low,(min(Val,Hi))))
  end;

var
  aIni: TIniFile;
begin
    // read defaults out of the registry
  with aConfig do
  begin
    aIni := TIniFile.Create('VidCapture.ini');

    bCenter := aIni.ReadBool('Configs', 'CenterImage', TRUE);
    bToolBar := aIni.ReadBool('Configs', 'ToolBar', TRUE);
    bStatusBar := aIni.ReadBool('Configs', 'StatusBar', TRUE);
    bAutoSizeFrame := aIni.ReadBool('Configs', 'AutoSizeFrame', TRUE);
    iBackColor := aIni.ReadInteger('Configs', 'BackgroundColor', $C0C0C0);

    iWinX := aIni.ReadInteger('Configs', 'WindowXPos', CW_USEDEFAULT);
    if iWinX <> CW_USEDEFAULT then
      iWinX := LimitRange(iWinX, 0, GetSystemMetrics(SM_CXSCREEN) - 40);
    iWinY := aIni.ReadInteger('Configs', 'WindowYPos', 0);
    iWinY := LimitRange(iWinY, 0, GetSystemMetrics(SM_CYSCREEN) - 40);
    iWinCX := aIni.ReadInteger('Configs', 'WindowWidth', 320);
    iWinCX := LimitRange(iWinCX, 20, GetSystemMetrics(SM_CXSCREEN));
    iWinCY := aIni.ReadInteger('Configs', 'WindowHeight', 240);
    iWinCY := LimitRange(iWinCY, 20, GetSystemMetrics(SM_CYSCREEN));
    iWinShow := aIni.ReadInteger('Configs', 'WindowShow', SW_SHOWDEFAULT);
    iWinShow := LimitRange(iWinShow, SW_SHOWNORMAL, SW_SHOWDEFAULT);

    bOverlay := aIni.ReadBool('Configs', 'OverlayWindow', FALSE);
    bLive := aIni.ReadBool('Configs', 'LiveWindow', TRUE);
    aIni.Free;
  end;
end;

procedure vidcapWriteProfile(aConfig: TConfigRec);
var
  aIni: TIniFile;
begin
    // read defaults out of the registry
  with aConfig do
  begin
    aIni := TIniFile.Create('VidCapture.ini');

    aIni.WriteBool('Configs', 'CenterImage', bCenter);
    aIni.WriteBool('Configs', 'ToolBar', bToolBar);
    aIni.WriteBool('Configs', 'StatusBar', bStatusBar);
    aIni.WriteBool('Configs', 'AutoSizeFrame', bAutoSizeFrame);
    aIni.WriteInteger('Configs', 'BackgroundColor', iBackColor);

    aIni.WriteInteger('Configs', 'WindowXPos', iWinX);
    aIni.WriteInteger('Configs', 'WindowYPos', iWinY);
    aIni.WriteInteger('Configs', 'WindowWidth', iWinCX);
    aIni.WriteInteger('Configs', 'WindowHeight', iWinCY);
    aIni.WriteInteger('Configs', 'WindowShow', iWinShow);

    aIni.WriteBool('Configs', 'OverlayWindow', bOverlay);
    aIni.WriteBool('Configs', 'LiveWindow', bLive);
    aIni.Free;
  end;
end;

//initialise settings from the profile used AFTER window creation time

procedure vidcapReadSettingsProfile(var aCapParms: TCAPTUREPARMS);
var
  aIni: TIniFile;
begin
    // read defaults out of the registry
  with aCapParms do
  begin
    aIni := TIniFile.Create('VidCapture.ini');

    //mmGetProfileString(gachAppTitle, "CaptureFile", "",
    //      gachCaptureFile, sizeof(gachCaptureFile));
    //mmGetProfileString(gachAppTitle, "MCIDevice", "VideoDisc",
    //      gachMCIDeviceName, sizeof(gachMCIDeviceName));
    dwRequestMicroSecPerFrame :=
      aIni.ReadInteger('SetParams', 'MicroSecPerFrame', DEF_CAPTURE_RATE);
    fCaptureAudio := False; //aIni.ReadBool('SetParams', 'CaptureAudio', False);
    fLimitEnabled := aIni.ReadBool('SetParams', 'LimitEnabled', FALSE);
    wTimeLimit := aIni.ReadInteger('SetParams', 'TimeLimit', 30);
    fMCIControl := aIni.ReadBool('SetParams', 'MCIControl', FALSE);
    fStepMCIDevice := aIni.ReadBool('SetParams', 'StepMCIDevice', FALSE);
    dwMCIStartTime := aIni.ReadInteger('SetParams', 'MCIStartTime', 10000);
    dwMCIStopTime := aIni.ReadInteger('SetParams', 'MCIStopTime', 20000);
    fStepCaptureAt2x := aIni.ReadBool('SetParams', 'StepCapture2x', FALSE);
    wStepCaptureAverageFrames :=
      aIni.ReadInteger('SetParams', 'StepCaptureAverageFrames', 3);
    AVStreamMaster :=
      aIni.ReadInteger('SetParams', 'AVStreamMaster', 0); //AVSTREAMMASTER_NONE);
    fUsingDOSMemory := aIni.ReadBool('SetParams', 'CaptureToDisk', TRUE);
    dwIndexSize :=
      aIni.ReadInteger('SetParams', 'IndexSize', 34952);
    aIni.Free;
  end;
end;

procedure vidcapWriteSettingsProfile(aCapParms: TCAPTUREPARMS);
var
  aIni: TIniFile;
begin
    // read defaults out of the registry
  with aCapParms do
  begin
    aIni := TIniFile.Create('VidCapture.ini');

    aIni.WriteInteger('SetParams', 'MicroSecPerFrame', dwRequestMicroSecPerFrame);
    aIni.WriteBool('SetParams', 'CaptureAudio', fCaptureAudio);
    aIni.WriteBool('SetParams', 'LimitEnabled', fLimitEnabled);
    aIni.WriteInteger('SetParams', 'TimeLimit', wTimeLimit);
    aIni.WriteBool('SetParams', 'MCIControl', fMCIControl);
    aIni.WriteBool('SetParams', 'StepMCIDevice', fStepMCIDevice);
    aIni.WriteInteger('SetParams', 'MCIStartTime', dwMCIStartTime);
    aIni.WriteInteger('SetParams', 'MCIStopTime', dwMCIStopTime);
    aIni.WriteBool('SetParams', 'StepCapture2x', fStepCaptureAt2x);
    aIni.WriteInteger('SetParams', 'StepCaptureAverageFrames', wStepCaptureAverageFrames);
    aIni.WriteInteger('SetParams', 'AVStreamMaster', AVStreamMaster);
    aIni.WriteBool('SetParams', 'CaptureToDisk', fUsingDOSMemory);
    aIni.WriteInteger('SetParams', 'IndexSize', dwIndexSize);
    aIni.Free;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -