Using the VFW

Please discuss general Delphi programming topics here.

Using the VFW

Postby sax » April 3rd, 2014, 6:57 am

Hi there.
I have problems using vfw.pas namely I would like to merge the two avi video together. Tmy_AVI_Tool Class has compiled as follows:

Code: Select all
uses ..., vfw;
...
type
  Tmy_AVI_Tool=Class
  private
    { Private declarations }
    m_IsPlaying: Boolean;
    m_File: PAVIFile;
    m_FileName: string;   
    m_PlayerHWND: HWND;
  public
   { Public declarations }
   m_Stream: PAVIStream;
   constructor Create(datoteka: String);
   destructor Destroy();override;
   function LoadAVI():Boolean;
   procedure Merge(parent: HWND; stream1, stream2: PAVIStream);
  published
   { Published declarations }
  end;
 
implementation
 
constructor Tmy_AVI_Tool.Create(datoteka: String);
begin
  m_IsPlaying:=False;
  m_Stream:=nil;
  m_FileName:=datoteka;
end;
 
destructor Tmy_AVI_Tool.Destroy();
begin
  if (m_Stream<>nil) then
  begin
    AVIStreamRelease(m_Stream);
    m_Stream:=nil;
  end;
  inherited Destroy;
end;
 
function Tmy_AVI_Tool.LoadAVI():Boolean;
begin
  // odpri AVi datoteko
  new(m_Stream);
  if (AVIFIleOpen(m_File, Pchar(m_FileName), OF_READ or OF_WRITE,nil)<>0) then
  begin
    if (AVIFILEGetStream(m_File, m_Stream, streamtypeVIDEO, 0)=AVIERR_NODATA) then
      Result:=False;
  end else
  begin
    // nisem uspel odpreti AVI datoteke
    AVIFileRelease(m_File);
    Result:=false;
  end;
end;
 
procedure Tmy_AVI_Tool.Merge(parent: HWND; stream1, stream2: PAVIStream);
var
  p: PAVIStream;
  dolp, dolp2: DWORD;
  dol, dol2: Longint;
  startp2: DWORD;
  start2: Longint;
begin
  new(p);
  if(CreateEditableStream(p, stream1)=0) then
  begin
    dolp:=AVIStreamLength(p);
    dolp2:=AVIStreamLength(stream2);
    startp2:=AVIStreamStart(stream2);
    if (EditStreamPaste(p, @dolp, @dolp2, stream2, start2, 0)<>0) then
    begin
    MessageBox(parent,'Združevanje AVI-jev ni uspelo!', 'Napaka pri združevanju!', MB_ICONERROR);
        exit;
    end;
  end;
end;




Then from the Main form call as follows:


Code: Select all
procedure TForm1.Button2Click(Sender: TObject);
var
    AVI1: Tmy_AVI_Tool;
    AVI2: Tmy_AVI_Tool;
    MergedAVI: Tmy_AVI_Tool;
    datoteka: String;
begin
    datoteka:='d:\video1.avi';
    AVI1:=Tmy_AVI_Tool.Create(datoteka);
    AVI1.LoadAVI();
    datoteka:='d:\video2.avi';
    AVI2:=Tmy_AVI_Tool.Create(datoteka);
    AVI2.LoadAVI();
    datoteka:='d:\merged.avi';
    MergedAVI:=Tmy_AVI_Tool.Create(datoteka);
    MergedAVI.Merge(Self.ClientHandle, AVI1.m_Stream, AVI2.m_Stream);
end;


That is, for each video object Tmy_AVI_Tool create and upload a video of him LoadAVI (), which opens a file and assigns the pointer address m_Stream Stream Video

Code: Select all
function    AVIFileGetStream(pfile: PAVIFILE; var ppavi: PAVISTREAM; fccType: DWORD; lParam: DWORD): HResult; stdcall;


The problem is when calling the procedure Merge namely the CreateEditableStream (p, stream1)
Code: Select all
function    CreateEditableStream(var ppsEditable: PAVISTREAM; psSource: PAVISTREAM): HResult; stdcall;


Where me an error message:
Project AVI.exe raised EXCEPTION class EAccessViolation with message 'Access violation at address 70E30292 in module' AVIFIL32.DLL '. Read of address 0000000C. ", Although stram1 an address (for example, $ 16D50B0).

Obviously there is something wrong with the transmission parameters stream1 and stream2, I do not know what?


lp Sax
sax
Member
Member
 
Posts: 1
Joined: April 3rd, 2014, 6:55 am

Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron