const
VCDFlag: array[0..3] of Byte = ($00,$00,$01,$BB);
function TForm1.GetHeadPos(AStm: TStream): Integer;
var
BufCounts, CurPos, I: Integer;
ReadCounts, CTimes: Integer;
buf: array[0..4095] of Byte;
begin
AStm.Seek(0, soFrombegin
ning);
CTimes := AStm.Size div 4096;
Result := 0;
for Bufcounts := 0 to CTimes - 1do
begin
ReadCounts := AStm.Read(buf[0], 4096);
for I := 0 to ReadCounts - 1do
begin
if (buf = VCDFlag[0]) and (buf[I + 1] = VCDFlag[1]) and
(buf[I + 2] = VCDFlag[2]) and (buf[I + 3] = VCDFlag[3]) then
begin
Result := AStm.Seek(BufCounts * 4096 + I - 12, soFrombegin
ning);
Exit;
end;
end;
end;
end;
procedure TForm1.VCDToMpg(const src, des: string);
var
fssrc: TFileStream;
fsdes: TFileStream;//TMemoryStream;
begin
Pos: Integer;
ReadCounts: Integer;
I, CTimes: Integer;
Buf: array[0..2323] of Char;
begin
fssrc := TFileStream.Create(src, fmOpenRead);
fsdes := TFileStream.Create(des, fmCreate);
try
begin
Pos := GetHeadPos(fssrc);
fssrc.Seek(begin
Pos, soFrombegin
ning);
CTimes := (fssrc.Size - begin
Pos) div 2352;
for I := 0 to CTimes - 1do
begin
Application.ProcessMessages;
fssrc.Read(buf[0], 2324);
fsdes.Write(buf[0], 2324);
fssrc.Seek(28, soFromCurrent);
//(2352 * I, soFrombegin
ning);
Application.ProcessMessages;
//fsdes.CopyFrom(fssrc, 2324);
end;
//fsdes.SaveToFile(des);
finally
fssrc.Free;
fsdes.Free;
end;
end;