avi转换为asf可以做到(用控件),但asf转换为avi好像不可以吧(没见过)!
下面的代码都是随手贴的,不知道是否可行,不清楚ASF文件的具体格式,纯粹就是流的截取和合并!
//有的asf文件需要截取asf流中间的一部分部分出来,应该如何解决?
用这个过程试试!
procedure Splitfile( const sourcefilename: String;
blocksize: Longint );
var
targetfilename: String;
filecounter: Integer;
bytesRemaining, bytesToWrite: LongInt;
source, target: TFileStream;
begin
if not FileExists( sourcefilename ) or (blocksize < = 0) then
Exit;
source := TFileStream.Create( sourcefilename, fmOpenRead or fmShareDenyNone);
try
filecounter := 0;
bytesRemaining := source.Size;
while bytesRemaining > 0do
begin
targetfilename := ChangeFileExt( sourcefilename, Format('.%.3d', [filecounter]));
if blocksize < bytesRemaining then
bytesToWrite := blocksize
else
bytesToWrite := bytesRemaining;
target := TFileStream.Create( targetfilename, fmCreate );
try
target.CopyFrom( source, bytesToWrite );
bytesRemaining := bytesRemaining - bytesToWrite;
Inc( filecounter );
finally
target.Free;
end;
end;
finally
source.Free;
end;
end;
//多个asf文件需要合成为一个大的asf流文件,应该如何解决?
procedure TForm1.Button1Click(Sender: TObject);
var
mem2,mem1:tfilestream;
ss:tmemorystream;
begin
mem1:=tfilestream.Create ('c:/1.asf', fmOpenRead );
mem2:=tfilestream.Create ('c:/2.asf', fmOpenRead );
ss:=tmemorystream.Create
ss.CopyFrom(mem1,mem1.size);
ss.Seek(0,soFromEnd);
ss.CopyFrom(mem2,mem2.size);
ss.SaveToFile('c:/3.asf');
mem2.Free;
mem1.Free;
end;
其实你就用Stream的Seek定位Pos,然后拷贝指定区域即可保存截取的流,流合并也如此!
我只是单纯从流的操作而言,也许这样会破坏数据结构。最好还是知道Asf文件的具体格式就好办了。
ASF_header structure 有吗??? 也许会有头绪!!!
呵呵!其实自己已经觉得有些无厘头了!
关注Other's Answer!