unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, MPlayer, ComCtrls;
type
TForm1 = class(TForm)
Mdplayer: TMediaPlayer;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
OpenDlg: TOpenDialog;
TrackBar: TTrackBar;
Button5: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure InitShow;
Procedure UpdataTrackBar ;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses VFW;
{$R *.dfm}
var
CurrentPos : Integer;
retc : Integer;
pfile : PAVIFile;
pfile1 : PAVIFile;
gapavi ,psCompressed : PAVIStream; // the current stream
gapavi1 : PAVIStream; // the current stream
gapgf : PGETFRAME; // data for decompressing video
lpbi : PBITMAPINFOHEADER;
bits : PChar;
hBmp : HBITMAP;
AviInfo: TAVIFILEINFOW;
m_nTimeFrame:integer;
strhdr:tAVISTREAMINFO;
opts:tAVICOMPRESSOPTIONS;
aopts
AVICOMPRESSOPTIONS ;
size:longint;
dibs: DIBSECTION;
sbm :integer;
pBMIInfo: PBITMAPINFO;
length, lengthen
d:integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
pBMIInfo := AllocMem(sizeof(TBITMAPINFO)+ (255 * sizeof(TRGBQuad)));
//设定BMP的头信息
pBMIInfo^.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
pBMIInfo^.bmiHeader.biWidth := 352;
pBMIInfo^.bmiHeader.biHeight := 288;
pBMIInfo^.bmiHeader.biPlanes := 1;
pBMIInfo^.bmiHeader.biBitCount := 24;
pBMIInfo^.bmiHeader.biCompression := BI_RGB;
pBMIInfo^.bmiHeader.biSizeImage := 0;
pBMIInfo^.bmiHeader.biXPelsPerMeter := 0;
pBMIInfo^.bmiHeader.biYPelsPerMeter := 0;
pBMIInfo^.bmiHeader.biClrUsed := 0;
pBMIInfo^.bmiHeader.biClrImportant := 0;
end;
Procedure Tform1.UpdataTrackBar ;
begin
TrackBar.min := MdPlayer.StartPos;
TrackBar.max := MdPlayer.Length;
TrackBar.Position := MdPlayer.Position;
Label2.Caption := '当前位置: '
+Inttostr(MdPlayer.Position);
end;
procedure tForm1.InitShow ;
begin
with Mdplayerdo
begin
if FileName <> '' then
begin
Open;
TrackBar.Enabled := True;
UpdataTrackBar;
// TrackBar.SetFocus ;
Frames := 1;
label1.Caption :='文件名: ' +
FileName + #13#10 +' 总长度: '+ Inttostr(Length);
label1.Caption :=Label1.Caption +
#13#10 +' 起始位置: '+ Inttostr(StartPos)
end else
begin
Label1.Caption :='';
Label2.Caption :='';
end;
end;
if Mdplayer.FileName <> '' then
begin
length:=0;
lengthen
d:=Mdplayer.Length;
label3.caption:='起始位置:'+inttostr(length);
label4.caption:='终止位置:'+inttostr(lengthen
d);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MdPlayer.Close ;
TrackBar.Enabled := False;
label1.Caption := '';
label2.Caption := '';
if OpenDlg.Execute then
begin
mdPlayer.FileName := OpenDlg.FileName ;
InitShow ;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Length:=MdPlayer.position;
label3.caption:='起始位置:'+inttostr(length);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Lengthen
d:=MdPlayer.position;
label4.caption:='终止位置:'+inttostr(lengthen
d);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
MdPlayer.position:=Length ;
MdPlayer.EndPos:=Lengthen
d;
MdPlayer.Play;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a
dword;
begin
AVIFileInit;
//yuan
retc := AVIFileOpen(pfile1, PChar(Mdplayer.FileName),0, nil);
if retc <> 0 then
begin
AVIFileExit;
exit;
end;
retc := AVIFileGetStream(pfile1, gapavi1,0 , 0);
if retc <> AVIERR_OK then
begin
AVIFileRelease(pfile);
AVIFileExit;
exit;
end;
retc := AVIFileOpen(pfile, 'c:/text.avi', OF_WRITE or OF_CREATE, nil);
if (retc<>AVIERR_OK) then
begin
AVIFileExit();
exit;
end;
ZeroMemory(@strhdr,sizeof(strhdr));
strhdr.fccType := streamtypeVIDEO;// stream type
strhdr.fccHandler := 0;
strhdr.dwScale := 1000;
strhdr.dwRate := 30000;
strhdr.dwSuggestedBufferSize := 352 * 288 * 3;
strhdr.rcFrame:=Rect(0,0,352,288);
// TheRect := Rect(10,10,100,100);
SetRect(strhdr.rcFrame, 0, 0, 352, 288);
retc:=AVIFileCreateStream(pfile, gapavi, @strhdr);
if retc <> AVIERR_OK then
begin
AVIFileRelease(pfile);
AVIFileExit;
exit;
end;
ZeroMemory(@opts,sizeof(opts));
aopts:= @opts ;
if not AVISaveOptions(panel1.Handle, 0, 1,
gapavi,
aopts)
then
exit;
// opts.fccHandler:=mmioFOURCC('d','i','v','x');
retc := AVIMakeCompressedStream(psCompressed, gapavi, @opts, nil);
if (retc <> AVIERR_OK) then
begin
exit;
end;
retc := AVIStreamSetFormat(psCompressed, 0,pBMIInfo, sizeof(pBMIInfo^));
//circle
CurrentPos:= length;
for m_nTimeFrame:=length to lengthen
ddo
begin
gapgf := AVIStreamGetFrameOpen(gapavi1, nil);
if gapgf = nil then
begin
AVIStreamGetFrameClose(gapgf);
AVIStreamRelease(gapavi);
AVIFileRelease(pfile);
AVIStreamRelease(gapavi1);
AVIFileRelease(pfile1);
AVIFileExit;
end;
lpbi := AVIStreamGetFrame(gapgf, CurrentPos);
if lpbi = nil then
begin
AVIStreamGetFrameClose(gapgf);
AVIStreamRelease(gapavi);
AVIFileRelease(pfile);
AVIStreamRelease(gapavi1);
AVIFileRelease(pfile1);
AVIFileExit;
end;
bits := Pointer(Integer(lpbi) + sizeof(TBITMAPINFOHEADER));
hBmp := CreateDIBitmap(
GetDC(memo1.Handle), // handle of device context
lpbi^, // address of bitmap size and format data
CBM_INIT, // initialization flag
bits, // address of initialization data
PBITMAPINFO(lpbi)^, // address of bitmap color-format data
DIB_RGB_COLORS );
//image1.Picture.Bitmap.Handle:=hBmp;
// sbm := GetObject(image1.Picture.Bitmap.Handle,sizeof(dibs),@dibs);
retc:=AVIStreamWrite(psCompressed, // stream pointer
m_nTimeFrame-length, // time of this frame
1, // number to write
// @dibs.dsBmih ,
lpbi,
352 * 288 * 3, // lpbi->biSizeImage, // size of this frame
AVIIF_KEYFRAME, // flags....
nil,
nil
);
// m_nTimeFrame:=m_nTimeFrame+1;
AVIStreamGetFrameClose(gapgf);
CurrentPos:=CurrentPos+1;
end;
Form1.Memo1.Lines.Add(Format('text.avi Framstart: %d FrameEnd: %d',
[AVIStreamStart(gapavi), AVIStreamEnd(gapavi)]));
AVIStreamRelease(gapavi);
AVIStreamRelease(psCompressed);
AVIFileRelease(pfile);
AVIStreamRelease(gapavi1);
AVIFileRelease(pfile1);
AVIFileExit;
end;
end.