我只粗略贴出部份相关内容
var
FileHeader: Array[0..MAX_CHANNELS - 1, 0..200 - 1] Of UCHAR;
//文件头
FileHeaderLen: Integer;
//文件头长度
CurrentFileLen: Array[0..MAX_CHANNELS - 1] Of ULONG;
//当前文件长度
Function Stream_Read_CallBack(ChannelNumber: UINT;
Context: Pointer): Integer;
Cdecl;
begin
TFrmMain(Context).OnDataReady(ChannelNumber, 0);
Result := 0;
end;
Function TFrmMain.OnDataReady(ChannelNum: UINT;
lparam: Integer): Integer;
Stdcall;
Var
StreamBuf: Array[0..BufSize - 1] Of UCHAR;
Status, Len, FrameType: Integer;
begin
Result := 0;
Len := SizeOf(StreamBuf);
Status := Sdk.ReadStreamData(ChannelHandle[ChannelNum], StreamBuf, @Len, @FrameType);
If Status = -1 then
Exit;
Case FrameType Of
PktSysHeader:
begin
//保留文件头备用
FillChar(FileHeader[ChannelNum], SizeOf(FileHeader[ChannelNum]), #0);
CopyMemory(@FileHeader[ChannelNum], @StreamBuf, Len);
FileHeaderLen := Len;
end;
end;
Inc(CurrentFileLen[ChannelNum], Len);
If Succeeded(Status) then
ChangeFileName(ChannelNum, Len);
FileWrite(FileHandle[ChannelNum], StreamBuf, Len);
end;
//切换文件
Procedure TFrmMain.ChangeFileName(ChannelNum, Len: Integer);
Var
CurrSize: LongWord;
IsChange: Boolean;
FilePath: String;
EndCode: ULONG;
begin
IsChange := False;
CurrSize := 100 * 1024 * 1024;
If CurrentFileLen[ChannelNum] > CurrSize then
//文件上限
IsChange := True
else
If GetDiskFree(CurrDrive[ChannelNum]) <= MinDiskSize then
IsChange := True;
If IsChange then
begin
EndCode := End_Code;
FileWrite(FileHandle[ChannelNum], EndCode, SizeOf(EndCode));
FileClose(FileHandle[ChannelNum]);
FilePath := GenerateFileName(ChannelNum);
If FileExists(FilePath) then
DeleteFile(FilePath);
FileHandle[ChannelNum] := FileCreate(FilePath);
FileWrite(FileHandle[ChannelNum], FileHeader[ChannelNum], FileHeaderLen);
CurrentFileLen[ChannelNum] := FileHeaderLen;
Inc(CurrentFileLen[ChannelNum], Len);
end;
end;
开始录像
FilePath := 'd:/xx.mpg';
If Length(FilePath) < 3 then
Exit;
If FileExists(FilePath) then
DeleteFile(FilePath);
FileHandle[ChannelNum] := FileCreate(FilePath);
If FileHandle[ChannelNum] = -1 then
begin
MsgErr('无法打开文件:' + FilePath);
Exit;
end;
SetDSP(ChannelNum);
CurrentFileLen[ChannelNum] := 0;
Sdk.StartVideoCapture(ChannelHandle[ChannelNum]);
FormCreate事件
Sdk.RegisterStreamReadCallback(Stream_Read_CallBack, self);