给你切割AVI的关键部分代码吧,从一个C语言代码翻译过来的.合并的话应该反过来即可.
MPEG的也一样.
http://www.138soft.com/htm/AuthorSoft/download/mpegproducer.zip
rocedure fnChopAvi(FileName:String);
var
FileStream,FileStreamWrite:TFileStream;
nOriginallistOffset:integer;
nFrameCount,nExcessFrameCount:integer;
nAudioFrameCount,nExcessAudioFrameCount:integer;
caTempFilename:String;//tmpxxxxx.avi
//save previous movi offset, used in idx1 offset modifing
nThismoviOffset:integer;
StrTemp:String;//=caBufChar[0]+caBufChar[1]+caBufChar[2]+caBufChar[3];
i,j:integer;
TempByte:Byte;
nTempPosidx1:integer;
//used inside "for loop" bellow
nTempInt:integer;//more temp var.
nSizeTillidx1:integer;
nTotalSize:integer;
nNowOffset:integer;
begin
FileStream:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
nOriginallistOffset := naListOffset[2];
//<<<<<<<<<<<<<<<<<
//notice these line, the value has been added for convinience
//>>>>>>>>>>>>>>>>>
inc(naListOffset[1],12);//move offset to movi data, 01wb...
inc(naListOffset[2],8);//move offset to idx1 data
naListOffset[5] := naListOffset[1];
//chopavi in while loop
while(TRUE)do
begin
nFrameCount:=0;nExcessFrameCount:=0;
nAudioFrameCount:=0;nExcessAudioFrameCount:=0;
//save previous movi offset, used in idx1 offset modifing
nThismoviOffset := naListOffset[5];
//==============calculate how many frame should be cut in one file========
FileStream.Seek(naListOffset[2],soFrombegin
ning);
//how many frame should be in a single file
//any single file should be start with keyframe, virtualdub said.
while(True)do
begin
if(FileStream.Position >= naListOffset[3]) then
//reach JUNK
begin
naListOffset[4] := FileStream.Position;
Break;
end;
FileStream.Read(caBufChar,4);//jump 01wb or 00dc
StrTemp:=caBufChar[0]+caBufChar[1]+caBufChar[2]+caBufChar[3];
//skip audio frame
if UpperCase(StrTemp)=(UpperCase('01wb')) then
begin
Inc(nAudioFrameCount);
FileStream.Seek(12,soFromCurrent);//move to next index
continue;
end
else
//video frame
begin
FileStream.Read(nBufInt,Sizeof(integer));
FileStream.Seek(8,soFromCurrent);
if(nBufInt = $10) then
//is keyframe
begin
if(nFrameCount <= LEAST_FRAME) then
begin
inc(nFrameCount);
continue;
end
else
begin
//is keyframe &&
is larger than LEAST_FRAME
//check if previous frame is audio frame
FileStream.Seek(-32,soFromCurrent);
FileStream.Read(caBufChar,4);
StrTemp:=caBufChar[0]+caBufChar[1]+caBufChar[2]+caBufChar[3];
FileStream.Seek(28,soFromCurrent);
if UpperCase(StrTemp)<>UpperCase('01wb')then
//if previous not a audio frame
begin
inc(nFrameCount);
continue;
end;
//move pointer back 1 + 1 step backward
//because we count excess 1 keyframe
//and I pretend that before video keyframe is audio frame
//because virtualdub told that avi begin
with audio frame
//and save it in naListOffset[4]