Delphi/Windows SDK/API for video network transmission
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061207002859115.html
Use Delphi for the first time
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, VFW, JPEG, extctrls, stdctrls, idbasecomponent, idcomponent,
Idudpbase, IdUDPClient;
Type
Tform1 = Class (tform)
Button1: tbutton;
Button2: tbutton;
Panel1: tpanel;
Idudpclient1: tidudpclient;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Capwnd: thandle; // defines the capture window handle.
Capparms: tcaptureparms; // structure variable used to set device Properties
BMP info: tbitmapinfo; // BMP Image Information
Implementation
{$ R *. DFM}
Function framecallback (hwnd: hwnd; lpvhdr: pvideohdr): longint; stdcall;
VaR
HD: thandle;
JPG: tsf-image;
Memstream: tmemorystream;
Bitmap: tbitmap;
Begin // display data in image,
Bitmap: = tbitmap. Create;
Bitmap. Width: = BMP info. bmiheader. biwidth;
// New size of Bitmap
Bitmap. Height: = BMP info. bmiheader. biheight;
HD: = drawdibopen;
Drawdibdraw (HD, bitmap. Canvas. Handle, 0, 0, BMP info. bmiheader. biwidth, BMP info. bmiheader. biheight,
@ BMP info. bmiheader, lpvhdr. lpdata, 0, 0, BMP info. bmiheader. biwidth, BMP info. bmiheader. biheight, 0 );
Drawdibclose (HD );
// Send data
Memstream: = tmemorystream. Create;
JPG: = tsf-image. Create;
JPG. Assign (Bitmap );
JPG. compressionquality: = 10;
// JPG compression quality
JPG. effecneeded;
JPG. Compress;
JPG. savetostream (memstream );
JPG. Free;
// Because the UDP packet size limit exists, if the part is exceeded, it is not transmitted and can be sent several times
Form1.idudpclient1. broadcastenabled: = true; // Broadcast Function
If memstream. size> form1.idudpclient1. buffersize then
// Broadcast to the 192.168.0.x CIDR Block, port 9001
Form1.idudpclient1. sendbuffer ('192. 168.0.255 ', 192, memstream. Memory ^, form1.idudpclient1. buffersize)
Else
Form1.idudpclient1. sendbuffer ('192. 168.0.255 ', 192, memstream. Memory ^, memstream. size );
Memstream. Free;
Bitmap. Free;
End;
Procedure tform1.button1click (Sender: tobject );
Begin
Capwnd: = capcreatecapturewindow ('My Windows', ws_visible or ws_child, // window style
0, // X coordinate
0, // y coordinate
Panel1.width, // window width
Panel1.height, // window height
Panel1.handle, // window handle
0); // usually 0
If capwnd = 0 Then exit; // defines the frame capture callback function.
Capsetcallbackonframe (capwnd, framecallback );
Capparms. dwrequestmicrosecperframe: = 1;
Capparms. flimitenabled: = false;
Capparms. fcaptureaudio: = false;
Capparms. fmcicontrol: = false;
Capparms. fyield: = true;
Capparms. vkeyabort: = vk_escape;
Capparms. fabortleftmouse: = false;
Capparms. fabortrightmouse: = false; // make the settings take effect
Capcapturesetsetup (capwnd, @ capparms, sizeof (tcaptureparms ));
Cappreviewrate (capwnd, 33); // you can specify the video preview frequency.
Capcapturesequencenofile (capwnd); // if you want to capture a video stream, use a function to specify not to generate a file. Otherwise, an AVI file is automatically generated.
Capdriverconnect (capwnd, 0); // connect to the camera device. The second parameter is the serial number. When multiple display drivers are installed in the system Program The value is 0 to the total number of cameras. If there are multiple cameras, the value is 0-> 1-> 2 capgetvideoformat (capwnd, @ BMP info, sizeof (tbitmapinfo )); // obtain the video image data Header
Cappreviewscale (capwnd, true); // whether to scale
Capoverlay (capwnd, true); // specifies whether overlay mode is used. If true is used, false is cappreview (capwnd, true); end; Procedure tform1.button2click (Sender: tobject );
Begin captureabort (capwnd); // stop capturing
Capdriverdisconnect (capwnd); // disconnect the capture window from the drive
End;
End;
Compilation error:
[Warning] unit1.pas (66): Return Value of function 'framecallback' might be undefined
[Error] unit1.pas (80): incompatible types: 'cardinal' and 'integer'
[Error] unit1.pa( 101): Declaration expected but end of file found
[Fatal error] project1.dpr (6): cocould not compile used unit 'unit1. pa'
Can you change it!
Tcaptureparms, which of the Structure Variables do you have to define?
Did the controls encapsulated by others provide DLL installation by the factory?
Is the ActiveX control loaded with environment variables? Is the OCX control installed?
This is not a control
Is a video for Windows service provided by Microsoft,
VFW. Pas.
The tcaptureparms Structure Variable comes from VFW. Pas.
Tcaptureparms capparms compilation is also successful,
Because # include VFW. h in BCB
VFW is not easy to use
All obsolete
DirectShow now
Generally, acceleration outside TCP is used for control, and the effect is good ~
UDP is too troublesome