Solved

Real-time video capture using Delphi 2

Posted on 1997-09-07
9
492 Views
Last Modified: 2010-04-04
I want to be able to generate an AVI file of moving real-time video from a video camera which is attatched to my computer.  The AVI file will be about 5 minutes in length.  I also want to be able to pass the size of the AVI frame i.e. 160 * 120 or 320*240, etc as a parameter when I initialise the video capture routine.

I roughly know how to do it using C, but I am finding Delphi a problem and I don't want to have to use C DLL's in my code, the boss wouldn't be happy.

VERY URGENT!!!!!!!!!!!!!!
0
Comment
Question by:StuartB
  • 6
  • 3
9 Comments
 

Author Comment

by:StuartB
ID: 1344301
Edited text of question
0
 

Author Comment

by:StuartB
ID: 1344302
Edited text of question
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344303
Please submit more info.
You need create avi from Bitmaps or other things.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:StuartB
ID: 1344304
Edited text of question
0
 

Author Comment

by:StuartB
ID: 1344305
Edited text of question
0
 

Author Comment

by:StuartB
ID: 1344306
Adjusted points to 170
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1344307
Mail to me source in C then i translate this to Delphi.
Which version of Delphi ?
Now i don't know what you need. Do you need create avi from bitmaps in memory ? I don't know what is you'r video capture routine. I try do this fast but i connect to Ex-Ex only at 9:00am and 17:00 GMT.

mirek@izabell.itcomp.tpnet.pl
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 100 total points
ID: 1344308
Here is the translated source, but You must change variables for constans. The constans is defined in you'r header files.
I havn't Video Capture Hardware so i can't test this, and i can't say you whay you can't use other resolutions.


unit Capt;

Interface

uses
  Windows;

type
  TCaptureParams = record
    dwRequestMicroSecPerFrame : DWORD;
    fMakeUserHitOKToCapture   : BOOLEAN;
    wPercentDropForError      : word;
    fYield                    : boolean;
    dwIndexSize               : DWORD;
    wChunkGranularity         : word;
    fUsingDOSMemory           : Boolean;
    wNumVideoRequested        : word;
    fCaptureAudio             : Boolean;
    wNumAudioRequested        : word;
    vKeyAbort                 : word;
    fAbortLeftMouse           : Boolean;
    fAbortRightMouse          : Boolean;
    fLimitEnabled             : Boolean;
    wTimeLimit                : word;
    fMCIControl               : Boolean;
    fStepMCIDevice            : Boolean;
    dwMCIStartTime            : Dword;
    dwMCIStopTime             : Dword;
    fStepCaptureAt2x          : Boolean;
    wStepCaptureAverageFrames : word;
    dwAudioBufferSize         : DWord;
    fDisableWriteCache        : Boolean;
    AVStreamMaster            : word;
  end;
  PCaptureParams = ^TCaptureParams;


procedure SetVideoSize( hCaptureWindow : THandle; Width, Height : Integer );
// Sets the size of the image to capture into the AVI file.

(*
// i don't know what you need with this
// this proc is not used so i omit this
extern int _export WINAPI ImageProc( int FAR noLanes, int direction, int UK, int areaLen,
                                     int FAR *LenArray, int topCorr, int bottomCorr, int FAR *outCount);
*)

function CaptureAVI( hWndMain : THandle; Width, Height, FrameRate, AudioFlag, AudioBufSize,
                     CaptureTime, DoubRes : Integer; CaptureFile : LPSTR ) : THandle;
// Sets up and initiates the video capture sequence.

procedure AbortCaptureAVI( hCaptureWindow : THandle );
// Aborts the video capture sequence.

procedure StopCaptureAVI( hCaptureWindow : THandle );
// Stops the video capture sequence and saves the AVI file to the hard drive.




{ This functions need be imported but i don't know from which file
  I found so in they exist in schel32.dll but you must try this
  - You can find this in SDK !!}
function capSetVideoFormat( hCaptureWindow : THandle; bih : Pointer; sizeofbih: Integer ) : boolean;
function capCreateCaptureWindow( lpszWindowName : LPCSTR; dwStyle : DWORD; x, y, nWidth, nHeight : Integer;
                                 hWnd : THandle; nID : Integer ) : THandle;
procedure capCaptureGetSetup( hWnd : THandle; psCapParm : PCaptureParams; sizeofCAPPARMS : integer );
procedure capCaptureSetSetup(hwnd : THandle; psCapParms : PCaptureParams; wSize : integer);
procedure capFileSetCaptureFile(hwnd : THandle; szName : LPCSTR );


{ i don't know the value of this constans
  You must set correct values from vfw.h }
const
  WM_CAP_DRIVER_CONNECT = 0;
  WM_CAP_SEQUENCE       = 0;
  WM_CAP_ABORT          = 0;
  WM_CAP_STOP           = 0;

implementation

function  capSetVideoFormat; external 'Shell32.dll' name 'capSetVideoFormat';
function  capCreateCaptureWindow; external 'Shell32.dll' name 'capCreateCaptureWindow';
procedure capCaptureGetSetup; external 'Shell32.dll' name 'capCaptureGetSetup';
procedure capCaptureSetSetup; external 'Shell32.dll' name 'capCaptureSetSetup';
procedure capFileSetCaptureFile;  external 'Shell32.dll' name 'capFileSetCaptureFile';

procedure SetVideoSize( hCaptureWindow : THandle; Width, Height : Integer );
var bih : TBITMAPINFOHEADER;
begin
// This function was copied off the Microsoft MSDN library discs, but doesn't seem to work.
// If you have any insight into this it would be great.
// Rescale the frame size.
// Variable used to hold bitmap formatting info. for sizing the captured AVI frame.
  bih.biSize          := sizeof(TBITMAPINFOHEADER);
  bih.biCompression   := BI_RGB;
  bih.biWidth         := Width;
  bih.biHeight        := Height;
  bih.biPlanes        := 1;
  bih.biBitCount      := 8;
  bih.biSizeImage     := bih.biWidth * bih.biHeight * bih.biPlanes * bih.biBitCount div 8;
  bih.biXPelsPerMeter := 0;
  bih.biYPelsPerMeter := 0;
  bih.biClrUsed       := 0;
  bih.biClrImportant  := 0;
  if not capSetVideoFormat( hCaptureWindow, @bih, sizeof(bih) ) then
    if MessageBox( hCaptureWindow,
       'Video Formatting information has been rejected by your video driver hardware',
       'Incompatibility Warning',
       MB_APPLMODAL and MB_ICONINFORMATION and MB_OKCANCEL )=IDCANCEL then
      AbortCaptureAVI(hCaptureWindow);   // Aborts the capture process.
end;


function CaptureAVI( hWndMain : THandle; Width, Height, FrameRate, AudioFlag, AudioBufSize,
                     CaptureTime, DoubRes : Integer; CaptureFile : LPSTR ) : THandle;
var
  CapParms : TCaptureParams;
  hCaptureWindow : THandle;
begin
// Create a capture window.
  hCaptureWindow := capCreateCaptureWindow( 'Capture Window', WS_CHILD, 0, 0, Width, Height, hWndMain, 0);
// Attempt to rescale the frame size.  This function always seems to fail.
// If you have any insight into this I would be grateful.
  SetVideoSize(hCaptureWindow, Width, Height);

// Analyse system and initiate video drivers.
  SendMessage(hCaptureWindow, WM_CAP_DRIVER_CONNECT, 0, 0 );

// Gets the current state of the video capture control structure.
  capCaptureGetSetup(hCaptureWindow, @CapParms, sizeof(TCaptureParams));

// Overrides to the video capture control structure.
  CapParms.dwRequestMicroSecPerFrame := round( FrameRate * 4444.466666 );
  CapParms.fMakeUserHitOKToCapture := FALSE;
  CapParms.fYield := TRUE;
  CapParms.fCaptureAudio := boolean(AudioFlag);
  CapParms.vKeyAbort := NULL;
  CapParms.fAbortLeftMouse := FALSE;
  CapParms.fAbortRightMouse := FALSE;
  if(CaptureTime > 0) then
    begin
      CapParms.fLimitEnabled := TRUE;
      CapParms.wTimeLimit := CaptureTime;
    end
  else
    CapParms.fLimitEnabled := FALSE;

  CapParms.fStepCaptureAt2x := boolean(DoubRes);
  CapParms.dwAudioBufferSize := AudioBufSize;
//      CapParms.AVIStreamMaster = AVISTREAMMASTER_NONE;

// Set the overrides to the structure.
  capCaptureSetSetup(hCaptureWindow, @CapParms, sizeof(TCAPTUREPARAMS));

// Tells the capture function where to place the capture file.
  capFileSetCaptureFile(hCaptureWindow, CaptureFile);

// Capture video sequence.
  SendMessage(hCaptureWindow, WM_CAP_SEQUENCE, 0, 0 );


// returns handle to capture window to enable the calling application to stop the capture sequence.
  result := hCaptureWindow;

end;

procedure AbortCaptureAVI( hCaptureWindow : THandle );
begin
  SendMessage( hCaptureWindow, WM_CAP_ABORT, 0, 0 );
  DestroyWindow( hCaptureWindow );
end;

procedure StopCaptureAVI( hCaptureWindow : THandle );
begin
  SendMessage(hCaptureWindow, WM_CAP_STOP, 0, 0 );
  DestroyWindow(hCaptureWindow);
end;

end.
0
 

Author Comment

by:StuartB
ID: 1344309
Very fast service.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE2 application frozen on Windows 10 10 313
Path  to current project in Delphi. 2 80
DBGrid or StringGrid ? 6 91
can i put an image from resource into image tag ? 6 25
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question