線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2164
推到 Plurk!
推到 Facebook!

Video for Windows capture component

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-31 12:47:36 IP:61.218.xxx.xxx 未訂閱

VCL Components - TCapture

資料來源: http://www.hobbypages.net/vcl_tcapture.asp Clicky here to begin download of TCapture.ZIP Video for Windows capture component (BETA) That means it's in testing stages. It does not mean it is ready for real-world programming. You wanna test it - go for it. You wanna use it for real, use it at your own risk. I'll remove all this scary text when I deem it fully functional and bug free. That's not to say it isnt powerful and easy to use. Someone asked me to write a demo flaunting it's usefulness. So I did. This is not a finished product - please either report bugs to me, or fix them before even thinking about using this component in real-world products. Demo Available: Clicky here to begin download of DEMO (hpcam.zip) ScreenShot and source code: The reason I don't include a zipped project is simple .... too many builder versions. main header (main.h)

//---------------------------------------------------------------------------
#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include < Classes.hpp >
#include < Controls.hpp >
#include < StdCtrls.hpp >
#include < Forms.hpp >
#include < ComCtrls.hpp >
#include < ExtCtrls.hpp >
#include "Capture.h"
#include < MPlayer.hpp >
#include < Buttons.hpp >
#include < Menus.hpp >
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
        TPanel *Panel1;
        TPanel *Panel2;
        TPanel *Panel4;
        TStatusBar *StatusBar1;
        TCapture *Capture1;
        TMediaPlayer *MediaPlayer1;
        TLabel *Label1;
        TLabel *Label2;
        TBitBtn *BitBtn1;
        TBitBtn *BitBtn2;
        TMemo *Memo1;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
        TTimer *Timer1;
        TLabel *Label7;
        TButton *Button1;
        TButton *Button2;
        TButton *Button3;
        TCheckBox *CheckBox1;
        TButton *Button4;
        TCheckBox *CheckBox2;
        TCheckBox *CheckBox3;
        TGroupBox *GroupBox1;
        TRadioButton *RadioButton1;
        TRadioButton *RadioButton2;
        TEdit *Edit1;
        TBitBtn *BitBtn4;
        TCheckBox *CheckBox4;
        TProgressBar *ProgressBar1;
        TTrackBar *TrackBar1;
        TLabel *Label20;
        TLabel *Label21;
        TLabel *Label23;
        TComboBox *ComboBox1;
        TBevel *Bevel1;
        TCheckBox *CheckBox5;
        TLabel *Label10;
        TLabel *Label24;
        TButton *Button5;
        TButton *Button6;
        TCheckBox *CheckBox6;
        TButton *Button7;
        TBitBtn *BitBtn3;
        TCheckBox *CheckBox7;
        TButton *Button8;
        TButton *Button9;
        TMainMenu *MainMenu1;
        TMenuItem *Hardware;
        TMenuItem *DriverSelect1;
        TMenuItem *Format1;
        TMenuItem *Compression1;
        TMenuItem *Display1;
        TMenuItem *Capture2;
        TMenuItem *Start1;
        TMenuItem *Stop1;
        TMenuItem *Save1;
        TMenuItem *Connect1;
        TMenuItem *Disconnect1;
        TMenuItem *N1;
        TMenuItem *N2;
        TMenuItem *Exit1;
        TMenuItem *N3;
        TMenuItem *Snapshot1;
        TMenuItem *CopytoClipboard1;
        TMenuItem *N4;
        TMenuItem *ReloadPlayer1;
        TMenuItem *Help1;
        TMenuItem *Help2;
        TMenuItem *About1;
        TPaintBox *PaintBox1;
        TPanel *Panel3;
        TBitBtn *BitBtn5;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall BitBtn1Click(TObject *Sender);
        void __fastcall BitBtn2Click(TObject *Sender);
        void __fastcall Capture1Status(TObject *Sender, int iErrorID,
          AnsiString sErrorText);
        void __fastcall Capture1Yield(TObject *Sender);
        void __fastcall BitBtn3Click(TObject *Sender);
        void __fastcall Capture1Error(TObject *Sender, int iErrorID,
          AnsiString sErrorText);
        void __fastcall MediaPlayer1PostClick(TObject *Sender,
          TMPBtnType Button);
        void __fastcall MediaPlayer1Click(TObject *Sender,
          TMPBtnType Button, bool &DoDefault);
        void __fastcall Timer1Timer(TObject *Sender);
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall Button2Click(TObject *Sender);
        void __fastcall Capture1VideoStream(TObject *Sender,
          LPVIDEOHDR lpVHdr);
        void __fastcall Capture1AudioStream(TObject *Sender,
          LPWAVEHDR lpWHdr);
        void __fastcall BitBtn4Click(TObject *Sender);
        void __fastcall Button4Click(TObject *Sender);
        void __fastcall TrackBar1Change(TObject *Sender);
        void __fastcall FormResize(TObject *Sender);
        void __fastcall ComboBox1Change(TObject *Sender);
        void __fastcall Button3Click(TObject *Sender);
        void __fastcall Button5Click(TObject *Sender);
        void __fastcall Button6Click(TObject *Sender);
        void __fastcall Button7Click(TObject *Sender);
        void __fastcall Edit1KeyPress(TObject *Sender, char &Key);
        void __fastcall Button8Click(TObject *Sender);
        void __fastcall Button9Click(TObject *Sender);
        void __fastcall BitBtn5Click(TObject *Sender);
        void __fastcall Exit1Click(TObject *Sender);
private:        // User declarations
bool bUseTimestamp;
//AVIFILEINFO AviFileInfo;
public:                // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif    main form (main.cpp)
//---------------------------------------------------------------------------
#include < vcl.h >
#pragma hdrstop
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Capture"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
bUseTimestamp = false;
if(FileExists(Capture1->VideoFileName))
        {
        BitBtn3->Enabled = true;
        ReloadPlayer1->Enabled = true;
        }
MediaPlayer1->TimeFormat = tfMSF;
MediaPlayer1->FileName = Capture1->VideoFileName;
Panel3->Width = Capture1->CaptureStatus.uiImageWidth;
Panel3->Height = Capture1->CaptureStatus.uiImageHeight;
PaintBox1->Width = Panel3->Width;
PaintBox1->Height = Panel3->Height;
Label6->Caption = "1";
Capture1->EnumCapDrv();
for(int i=0; i < Capture1->pStringCapDrivers->Count; i  )
        {
        ComboBox1->Items->Add(Capture1->pStringCapDrivers->Strings[i]);
        }
Button4Click(Sender);//update CaptureParams
}
//---------------------------------------------------------------------------
/*Start capturing video*/
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
MediaPlayer1->Close();
BitBtn3->Enabled = false;
BitBtn5->Enabled = false;
ReloadPlayer1->Enabled = false;
Capture1->SetCaptureParamDefaults();
Capture1->UpdateParms();
Capture1->UseCallbackOnWaveStream = true;
Capture1->UseCallbackOnVideoStream = true;
Capture1->UseCallbackOnError = true;
Capture1->UseCallbackOnStatus = true;
Capture1->UseCallbackOnYield = true;
Capture1->StartCapture(true, (TObject*)Sender);
}
//---------------------------------------------------------------------------
/*Stop capturing video*/
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
BitBtn3->Enabled = false;
ReloadPlayer1->Enabled = false;
if(!Capture1->StopCapture())
        {
        Memo1->Lines->Add("STOPPING");
        }
}
//---------------------------------------------------------------------------
/*TNotifyEvent OnStatus*/
void __fastcall TForm1::Capture1Status(TObject *Sender, int iErrorID,
      AnsiString sErrorText)
{
StatusBar1->Panels->Items[1]->Text = sErrorText;
Memo1->Lines->Add(sErrorText);
if(StatusBar1->Panels->Items[1]->Text == "Capture End")
        {
        BitBtn4->Click();
        }
}
//---------------------------------------------------------------------------
/*TNotifyEvent OnYield*/
void __fastcall TForm1::Capture1Yield(TObject *Sender)
{
Application->ProcessMessages();
}
//---------------------------------------------------------------------------
/*Reload Player Button*/
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
HMMIO hFile;/*some stuff for Label 10 and 23*/
PAVIFILE anAVIfile;
AVIFileOpen(&anAVIfile,Capture1->VideoFileName.c_str(),
        OF_SHARE_DENY_NONE, NULL);    if ((hFile = mmioOpen(Capture1->VideoFileName.c_str(), NULL,
        MMIO_READ)) != NULL)
        {
        Label10->Caption = "Opened";// File opened successfully.
        }
        else
        {
        Label10->Caption = " Not Opened";// File cannot be opened.
        }
AVIFILEINFO  AviFileInfo;
AVIFileInfo(anAVIfile, &AviFileInfo, sizeof(AVIFILEINFO));
if(FileExists(Capture1->VideoFileName))
        {
        MediaPlayer1->Close();
        MediaPlayer1->FileName = Capture1->VideoFileName;
        MediaPlayer1->Open();
        Label21->Caption = Capture1->VideoFileName;
        Label23->Caption = AviFileInfo.szFileType;
        MediaPlayer1->Frames = 1;
        ProgressBar1->Max = MediaPlayer1->Length;
        TrackBar1->Max = MediaPlayer1->Length;
        TrackBar1->Enabled = true;
        }
  BitBtn5->Enabled = true;
}
//---------------------------------------------------------------------------
/*TNotifyEvent OnError*/
void __fastcall TForm1::Capture1Error(TObject *Sender, int iErrorID,
      AnsiString sErrorText)
{
StatusBar1->Panels->Items[1]->Text = sErrorText;
Memo1->Lines->Add(sErrorText);
}
//---------------------------------------------------------------------------
/*Adjust Label6 to show current position of player*/
void __fastcall TForm1::MediaPlayer1PostClick(TObject *Sender,
      TMPBtnType Button)
{
Label6->Caption = IntToStr(MediaPlayer1->Position);
}
//---------------------------------------------------------------------------
/*In case the TrackBar had focus - MediaPlayer doenst take focus OnClick*/
void __fastcall TForm1::MediaPlayer1Click(TObject *Sender,
      TMPBtnType Button, bool &DoDefault)
{
MediaPlayer1->SetFocus();
}
//---------------------------------------------------------------------------
/*Update AVI position label (Label6)*/
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label6->Caption = IntToStr(MediaPlayer1->Position);            ProgressBar1->Position = StrToInt(Label6->Caption);
        TrackBar1->Position = StrToInt(Label6->Caption);
}
//---------------------------------------------------------------------------
/*Driver Format Dialog*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Capture1->Format();
Panel3->Width = Capture1->CaptureStatus.uiImageWidth;
Panel3->Height = Capture1->CaptureStatus.uiImageHeight;
PaintBox1->Width = Panel3->Width;
PaintBox1->Height = Panel3->Height;
Capture1->MoveCaptureWindow();
//Repaint();
}
//---------------------------------------------------------------------------
/*Driver Source Dialog*/
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Capture1->Source();
Panel3->Width = Capture1->CaptureStatus.uiImageWidth;
Panel3->Height = Capture1->CaptureStatus.uiImageHeight;
PaintBox1->Width = Panel3->Width;
PaintBox1->Height = Panel3->Height;
Capture1->MoveCaptureWindow();
}
//---------------------------------------------------------------------------
/*TNotifyEvent OnVideoStream*/
void __fastcall TForm1::Capture1VideoStream(TObject *Sender,
      LPVIDEOHDR lpVHdr)
{
int a = lpVHdr->dwTimeCaptured;
Label5->Caption = IntToStr(a);//the one next to "Recording Time"
}
//---------------------------------------------------------------------------
/*Capture1 Callback OnAudioStream*/
void __fastcall TForm1::Capture1AudioStream(TObject *Sender,
      LPWAVEHDR lpWHdr)
{
int a = lpWHdr->dwBytesRecorded;  //buffer size
Label4->Caption = IntToStr(a);//"Audio Buffer Size ="
}
//---------------------------------------------------------------------------
/*TNotifyEvent OnFormShow*/
/*Save Button*/
void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
BitBtn3->Enabled = true;
ReloadPlayer1->Enabled = true;
Label21->Caption = Capture1->VideoFileName;
int i = Capture1->SaveCapture();
if(i == 0)
        {
        StatusBar1->Panels->Items[0]->Text = "Save Failed";
        }
        else
        {
        StatusBar1->Panels->Items[0]->Text = "Save Succeeded";
        }
}
//---------------------------------------------------------------------------
/*Update Capture1->CaptureParams (CAPTUREPARAMS)*/
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if(CheckBox1->Checked)
        {
        Capture1->CaptureParams.fLimitEnabled = true;
        Capture1->CaptureParams.wTimeLimit = StrToInt(Edit1->Text);
        }
        else
        {
        Capture1->CaptureParams.fLimitEnabled = false;
        }
if(CheckBox2->Checked)
        {
        Capture1->LeftMouseAbort = true;
        }
        else
        {
        Capture1->LeftMouseAbort = false;
        }
if(CheckBox3->Checked)
        {
        Capture1->RightMouseAbort = true;
        }
        else
        {
        Capture1->RightMouseAbort = false;
        }
if(RadioButton1->Checked)
        {
        Capture1->MicroSecPerFrame = Capture1->Fast_fps;
        }
if(RadioButton2->Checked)
        {
        Capture1->MicroSecPerFrame = Capture1->Slow_fps;
        }
if(CheckBox4->Checked)
        {
        Capture1->PromptToSave = true;
        }
        else
        {
        Capture1->PromptToSave = false;
        }
if(CheckBox5->Checked)
        {
        Capture1->CaptureAudio = true;
        }
        else
        {
        Capture1->CaptureAudio = false;
        }
if(CheckBox6->Checked)
        {
        Capture1->MustYield = true;
        }
        else
        {
        Capture1->MustYield = false;
        }
if(CheckBox7->Checked)
        {
        bUseTimestamp =  true;
        }
        else
        {
        bUseTimestamp = false;
        }
Capture1->SetCaptureParamDefaults();
}
//---------------------------------------------------------------------------
/*Moves the position in the MediaPlayer*/
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
if(MediaPlayer1->Position != -1)
        {
        if(TrackBar1->Focused() == true)
                {
                MediaPlayer1->Position = TrackBar1->Position;
                }
        }
}
//---------------------------------------------------------------------------
/*having problems with the MediaPlayer output panel*/
void __fastcall TForm1::FormResize(TObject *Sender)
{
Panel3->Width = Capture1->CaptureStatus.uiImageWidth;
Panel3->Height = Capture1->CaptureStatus.uiImageHeight;
PaintBox1->Width = Panel3->Width;
PaintBox1->Height = Panel3->Height;
}
//---------------------------------------------------------------------------
/*Changing drivers? lets reset it*/
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
Capture1->Disconnect();
Capture1->Connect(Capture1->pStringCapDrivers->IndexOf(ComboBox1->Text));
}
//---------------------------------------------------------------------------
/*Open Compression Dialog*/
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Capture1->SetCompression();
}
//---------------------------------------------------------------------------
/*Open Display Dialog*/
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Capture1->GetDisplay();
}
//---------------------------------------------------------------------------
/*Grab a still image*/
void __fastcall TForm1::Button6Click(TObject *Sender)
{
if(bUseTimestamp)
        {
        TDateTime Time(Now());
        String s = ".bmp";
        String fname = Time.FormatString("mmddhnnss")   s;
        Capture1->Snapshot(fname.c_str());
        }
        else
        {
        Capture1->Snapshot("SnapShot.bmp");
        }
}
//---------------------------------------------------------------------------
/*copy still image to clipboard - Snapshot not required*/
void __fastcall TForm1::Button7Click(TObject *Sender)
{
Capture1->CopyToClipboard();
}
//---------------------------------------------------------------------------
/*keeps it numbers*/
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if(!isdigit(Key))
        {
        Key = NULL;
        }
}
//---------------------------------------------------------------------------
/*Connect button*/
void __fastcall TForm1::Button8Click(TObject *Sender)
{
Capture1->Connect(Capture1->pStringCapDrivers->IndexOf(ComboBox1->Text));
}
//---------------------------------------------------------------------------
/*Disconnect button*/
void __fastcall TForm1::Button9Click(TObject *Sender)
{
Capture1->Disconnect();
}
//---------------------------------------------------------------------------
/*
take a snapshot of a playback window AVIframe(saves as snapshot.dib)
this is not a quality image, since this is a demo of the TCapture
component - not a source for a high end AVI editor :-)
*/
void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{
//
TCanvas *cCanvas = new TCanvas;
cCanvas->Handle = GetDC(MediaPlayer1->Display->Handle);
Graphics::TBitmap *bitmap = new Graphics::TBitmap;
bitmap->Width = Panel3->Width;
bitmap->Height = Panel3->Height;
TRect src = MediaPlayer1->DisplayRect;
TRect dst = PaintBox1->ClientRect;
bitmap->Canvas->CopyRect(dst, cCanvas, src);
bitmap->SaveToFile(Capture1->StillImageFileName);
delete bitmap;
delete cCanvas;
}
//---------------------------------------------------------------------------
/*Closes program*/
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------     
As always - software made available here at the HobbyPages is always free - and royalty-free. For me, it's a learning experience, and a joy to be of service. TCapture VCL元件原始碼如下:

/*==================== Capture.cpp ================================
VERSION .07 beta - November 22,2002
The windows you create by using the TCapture VCL Component can perform the following tasks:    ?Capture audio and video streams to an audo-video interleaved (AVI) file.
?Connect and disconnect video and audio input devices dynamically.
?View a live incoming video signal by using the overlay or preview methods.
?Specify a file to use when capturing and copy the contents of the capture file to another file.
?Set the capture rate.
?Display dialog boxes that control the video source and format.
?Create, save, and load palettes.
?Copy images and palettes to the clipboard.
?Capture and save a single image as a device-independent bitmap (DIB).
The API documentations for AVI Capture can be found in the MS Help Files folder,
MMEDIA.HLP, topic "Video Capture"    Format = Video for Windows    VERSION CONTROL: www.hobbypages.net
ver .01 - 04 beta - unreleased to the public
        Malcolm Smith was the only one to see it in this state.
ver .05 beta - released  October 16, 2002
        original formula - no sugar added
ver .06 beta - released  November 20, 2002
        fixed user intervention for resizing events
        removed FrameData event - duplicated Satus event anyway
ver .07 beta - released November 22, 2002
        StartCapture(...) would stop after about 15 frames.
        This was caused by not reading the existing CAPTUREPARAMS
        before writing them. This was corrected.
        Changed a few other things - I forget now.
*/
//---------------------------------------------------------------------------
#include < vcl.h >
#pragma hdrstop
#include < stdio.h >
#include "Capture.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
static inline void ValidCtrCheck(TCapture *)
{
new TCapture(NULL);
}
//---------------------------------------------------------------------------
namespace Capture
{
        void __fastcall PACKAGE Register()
        {
                 TComponentClass classes[1] = {__classid(TCapture)};
                 RegisterComponents("HobbyPages", classes, 0);
        }
}
//---------------------------------------------------------------------------
/*CALLBACK Functions*/
//---------------------------------------------------------------------------
LRESULT CALLBACK ::OnErrorCallback(HWND hWnd, int nErrID, LPCSTR lpErrorText)
{
//TCapture Control;
TCapture *Control = reinterpret_castcapGetUserData(hWnd);
if (Control)
        {
        if(Control->fErrorCallback)
                {
                Control->fErrorCallback(Control, nErrID, lpErrorText);
                Control->sErrorText = lpErrorText;
                Control->iErrorNumber = nErrID;
                }
        }
return (LRESULT) true;
}
//---------------------------------------------------------------------------    LRESULT CALLBACK ::OnStatusCallback(HWND hWnd, int nMsgID, LPCSTR lpMessageText)
{
TCapture *Control = reinterpret_castcapGetUserData(hWnd);
if (Control)
        {
        if(Control->fStatusCallback)
                {
                Control->fStatusCallback(Control, nMsgID, lpMessageText);
                Control->sStatusMessageText = lpMessageText;
                Control->iStatusMessageID = nMsgID;
                }
        }    return (LRESULT) true;
}
//---------------------------------------------------------------------------    LRESULT CALLBACK ::OnVideoStreamCallback(HWND hWnd, LPVIDEOHDR lpVHdr)
{
TCapture *Control = reinterpret_castcapGetUserData(hWnd);
if (Control)
        {
        if(Control->fVideoStreamCallback)
                {
                Control->fVideoStreamCallback(Control, lpVHdr);
                Control->VideoHeader = lpVHdr;
                }
        }    return (LRESULT) true;
}
//---------------------------------------------------------------------------    LRESULT CALLBACK ::OnWaveStreamCallback(HWND hWnd, LPWAVEHDR lpWHdr)
{
TCapture *Control = reinterpret_castcapGetUserData(hWnd);
if (Control)
        {
        if(Control->fAudioStreamCallback)
                {
                Control->fAudioStreamCallback(Control, lpWHdr);
                Control->WaveHeader = lpWHdr;
                }
        }    return (LRESULT) true;
}
//---------------------------------------------------------------------------    LRESULT CALLBACK ::OnYieldCallback(HWND hWnd)
{
TCapture *Control = reinterpret_castcapGetUserData(hWnd);
if (Control)
        {
        if(Control->fYieldCallback)
                {
                Control->fYieldCallback(Control);
                }
        }    return (LRESULT) true;
}
//---------------------------------------------------------------------------
/*          TCapture in it's entirety                   */
//---------------------------------------------------------------------------
__fastcall TCapture::TCapture(TComponent* Owner)
        : TCustomControl(Owner)
{
Width = 320;
Height = 240;
Color = clNavy;
fPromptToSave = true;
/*Owner must be a form or panel (Parented Window Control)*/
if(!dynamic_cast(Owner))
        {
        throw Exception("Owner of the component must be a form or panel /n (Parented Window Control)");
        }
if(dynamic_cast(Owner))
        {
        this->Parent = dynamic_cast(Owner);
        this->Parent->HandleNeeded();
        HandleNeeded();
        }
/*component defaults*/
CaptureNoFile = false;
//false = StartCapture() writes an AVI, true = streams only
Scalable = false;
PreviewMode = true;
PreviewRate = 34; //setting default = 29.5 fps
UseCallbackOnError = false;
UseCallbackOnStatus = false;
UseCallbackOnVideoStream = false;
UseCallbackOnWaveStream = false;
UseCallbackOnYield = false;
fErrorCallback = NULL;
fStatusCallback = NULL;
fVideoStreamCallback = NULL;
fAudioStreamCallback = NULL;
fYieldCallback = NULL;
sVideoFileName = "video.avi";
sStillImageFileName = "snapshot.dib";    /*CAPTUREPARMS data members*/
Fast_fps = 33334; // 29.5 fps
Slow_fps = 66667; // 15.5 fps
MicroSecPerFrame = Slow_fps;//default
/*frames per second
these make it easier to set, you can use your own numbers
*/
PressOKtoStartCapture = false;
//true brings up a VFW dialogbox OK/cancel
PercentFramesDroppedForError = 20;//percent
MustYield = false;
/*
Yield flag. If this member is TRUE, the capture window spawns
a separate background thread to perform step and streaming capture.
The default value is FALSE.
Applications that set this flag must handle
potential reentry issues because the controls
in the application are not disabled while capture is in progress.
*/
MaxFrames = 0;
BlockSizeInBytes = 0;
CaptureAudio = true;
MaxAudioBuffers = 10;
AudioBufferSize = 0;
AVStreamMaster = AVSTREAMMASTER_NONE;
AbortKeycode = VK_ESCAPE;
LeftMouseAbort = false;
RightMouseAbort = true;
isTimeLimited = false;
WhatTimeLimit = 60;
DoesControl_MCI_Device = false;
UseStepCapture_MCI = false;
StartTime_MCI = 0;
StopTime_MCI = 0;
// StepCapture2x - see note
StepCapture2x = false;
/*
Double-resolution step capture flag. If this member is TRUE,
 the capture hardware captures at twice the specified resolution.
  (The resolution for the height and width is doubled.)
Enable this option if the hardware does not support
 hardware-based decimation and you are capturing in the RGB format.
*/
FrameSamplingAverage = 5;                if (!ComponentState.Contains(csDesigning))
        {
         Visible = false;
                        //ParentHandle = this->Handle;
                       ParentHandle = ((TWinControl*)Parent/*Owner*/)->Handle;
                 hwndVideo = capCreateCaptureWindow(
                        (LPSTR) "Video Capture",
                        WS_CHILDWINDOW | WS_VISIBLE,
                        Top, Left,
                        CaptureStatus.uiImageWidth,
                        CaptureStatus.uiImageHeight,
                        (HWND) ParentHandle,
                        (int) 2);
        }            if (!ComponentState.Contains(csDesigning))
        {
                pStringCapDrivers = new TStringList;
                SelectedDevice = -1;
                //establish a 'this' pointer to the window that owns the TCapture
                capSetUserData(hwndVideo, int(this));
                //optimize pallete
                capPaletteAuto(hwndVideo, 1000, 256);
                //update Driver Status
                if(Scalable)
                        {
                        CaptureStatus.fScale = 1;
                        }
                        else
                        {
                        CaptureStatus.fScale = 0;
                        }
                capGetStatus(hwndVideo, &CaptureStatus, sizeof(CAPSTATUS));            }
}
//---------------------------------------------------------------------------
__fastcall TCapture::~TCapture()
{
if (Connected)
        {
        capDriverDisconnect(hwndVideo);
        }
delete pStringCapDrivers;
}
//---------------------------------------------------------------------------
void __fastcall TCapture::AfterConstruction(void)
{
/*
this ties the Form's OnResize event to MoveCaptureWindow()
also see DoOnResizeEvent()
*/
if (FOnParentResize)  // reset .. saftey flag
        {
        dynamic_cast(Owner)->OnResize = FOnParentResize;
        FOnParentResize = NULL;
        }
if (dynamic_cast(Owner)) //we can hook.
        {
        FOnParentResize = dynamic_cast(Owner)->OnResize;
        dynamic_cast(Owner)->OnResize = DoOnResizeEvent;
        }    // debug - delete fPromptToSave = true;    Connect(0);// see note
/*
starts connected to first device found
If you want to change this (user settings)
Disconnect(), then Connect(yourint) on FormShow()
yourint loaded from the registry, or INI
*/
}
//---------------------------------------------------------------------------
void __fastcall TCapture::SetPreviewScalable(bool Scalable)
{
capPreviewScale(hwndVideo, Scalable);
capGetStatus(hwndVideo, &CaptureStatus, sizeof(CAPSTATUS));
}
//---------------------------------------------------------------------------
int __fastcall TCapture::EnumCapDrv(void)
{
char szDeviceName[80];
char szDeviceVersion[80];
char str[161];
int xcap;
xcap = 0;
pStringCapDrivers->Clear();
        do
                {
                if (capGetDriverDescription(xcap, szDeviceName, sizeof(szDeviceName),
                szDeviceVersion, sizeof(szDeviceVersion)))
                        {
                        sprintf (str, "%s, %s", szDeviceName, szDeviceVersion);
                        pStringCapDrivers->AddObject (str, (TObject *)xcap);
                        }
                else
                        {
                        break;
                        }
                xcap  ;
                }
        while (true);    return 0;
}
//---------------------------------------------------------------------------
void __fastcall TCapture::Disconnect(void)
{
if(capDriverDisconnect(hwndVideo));
Connected = false;
                        if(OnDisconnect)
                                {
                                OnDisconnect(this); //TNotifyEvent Handler
                                }
}
//---------------------------------------------------------------------------
void __fastcall TCapture::DoOnResizeEvent(TObject *Sender)
{
  // let form finish sizing ..
  if (FOnParentResize) FOnParentResize (Sender);
  // adjust ..
  MoveCaptureWindow();
}
//-------------------------------------------    //--------------------------------------------
void __fastcall TCapture::MoveCaptureWindow(void)
{
//if it's not on the form directly, adjust Top/Left to Parent
if(Parent->ClassParent() !=  __classid(TForm))
        {
        int x = Parent->Left;
        int y = Parent->Top;
        SetWindowPos(hwndVideo, NULL, Left   x, Top   y, CaptureStatus.uiImageWidth,
        CaptureStatus.uiImageHeight, SWP_NOZORDER | SWP_DRAWFRAME);
        }
}
//---------------------------------------------------------------------------
bool __fastcall TCapture::Connect(int Selected)
{
if (SelectedDevice != -1)
        {
        capPreview (hwndVideo, PreviewMode);
        capDriverConnect(hwndVideo, SelectedDevice);
        }
if (!capDriverConnect(hwndVideo, Selected))
        {
        Visible = false;
        return 0;
        }
capDriverGetCaps (hwndVideo, sizeof(CAPDRIVERCAPS), &CaptureDriverCaps);
capDlgVideoFormat(ParentHandle);
capGetStatus(hwndVideo, &CaptureStatus, sizeof(CAPSTATUS));
SetWindowPos(hwndVideo, NULL, Left, Top, CaptureStatus.uiImageWidth,
CaptureStatus.uiImageHeight, SWP_NOZORDER | SWP_DRAWFRAME);
capPreviewRate (hwndVideo, PreviewRate);
switch(PreviewMode)
        {
        case false:
                {                            if(CaptureDriverCaps.fHasOverlay)
                                {
                                        capOverlay(hwndVideo, true);
                                }
                        else
                                {
                                        capPreview (hwndVideo, PreviewMode);
                                        SelectedDevice = Selected;
                                }
                        break;
                }
        case true:
                {
                        capPreview (hwndVideo, PreviewMode);
                        SelectedDevice = Selected;
                        break;
                }
        }
        Connected = true;
        MoveCaptureWindow();
//TNotifyEvent Handler
if(OnConnect)
        {
        OnConnect(this);
        }
return 1;
}
//---------------------------------------------------------------------------
void __fastcall TCapture::Format(void)
{
if(Connected)
{
//CAPSTATUS CaptureStatus;
capDlgVideoFormat(hwndVideo);
capGetStatus(hwndVideo, &CaptureStatus, sizeof(CAPSTATUS));
//TNotifyEvent Handler
if(OnFormatChange)
        {
        OnFormatChange(this);
        }
}
this->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TCapture::Source(void)
{
capDlgVideoSource(hwndVideo);
capGetStatus(hwndVideo, &CaptureStatus, sizeof(CAPSTATUS));
//TNotifyEvent Handler
if(OnSourceChange)
        {
        OnSourceChange(this);
        }
}
//---------------------------------------------------------------------------
void __fastcall TCapture::GetDisplay(void)
{
if(!capDlgVideoDisplay(hwndVideo))
        {
                ShowMessage("This driver does not support a Video Dis
        
系統時間:2024-04-26 13:19:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!