DirectShow Interface Effects (2)
Generally, generally use the DirectShow interface to program the programming, initialize the interface, using the control function in the interface, and finally release the interface. (Of course, this is assumed here that you already have a unit you must have units, if you don't have, please ask for it online (Note: The following variables are not defined, you need to define your own use)
1) Initializing the interface part
First, you need to define the interface variables you need to use.
Graphbuilder: IGRAPHBUILDER;
MediaControl: iMediacontrol;
Mediaseeking: iMediaseEKing;
MediaPosition: IMEDIAPSITION;
MediaeventEx: iMediaEvent;
Basicaudio: ibasicaudio;
BasicVideo: ibasicvideo;
VideoWindow: iVideoWindow;
Samplegrabber: isamplegrabber;
VideoFramestep: iVideOframestep;
(1) Then you need to create a Filter Graph Manager instance using the CoCreateInstance function, CocreateInstance (Tguid_filtergraph), NIL, Clsctx_inproc_server,
Tguid (IID_IGRAPHBUILDER), Graphbuilder
Because you need to use the IsAmpleGrabber interface, you need to create a SampleGRabber instance.
Var Filter: ibasefilter;
CocreateInstance (CLSID_SAMPLEGRABBER, NIL, CLSCTX_INPROC_SERVER,
IID_IBASEFILTER, FILTER);
(2) Call QueryInterface function acquisition to get pointers, after the operation is controlled
Filter.QueryInterface (IID_ID_ISAMPLEGRABBER, SAMPLEGRABBER);
Graphbuilder.addfilter (Filter, 'Grabber');
Graphbuilder.QueryInterface (IID_IMEDIACONTROL, MediaControl);
Graphbuilder.QueryInterface (IID_IMEDIAPSITION, MedIaPosition);
Graphbuilder.QueryInterface (iid_imediaseeking, mediaseeping);
Graphbuilder.queryinterface (IID_IMEDIAEVENTEX, MediaEventex);
Graphbuilder.queryinterface (IID_IVIDEOFRAMESTEP, VideoFramestep);
Graphbuilder.Queryinterface (IID_IBASICAUDIO, BASICAUDIO);
Graphbuilder.Queryinterface (IID_IBASICVIDEO, BASICVIDEO);
Graphbuilder.queryinterface (IID_IVideoWindow, VideoWindow);
Of course, for the sake of safety, it can be successfully judged, give information, otherwise it is very likely that there is a problem that the clue cannot be found. Ok, everything is ready to be successful, you can enter the third step and start our control operation.
(3) Start control through the function provided by the interface
Oh, I almost forget an important thing, and two important things to do before calling QueryInterface above, first, to create a Unicode (Wide Character) string, save the file name. Var _wfile: array [0..max_path - 1] of wchar;
MultibyToWideChar (CP_ACP, 0, PCHAR (play file name), -1, @_wfile, max_path;
Then you need to success Renderfile to control the operation graphbuilder.renderfile (_wfile, nil);
Of course, when you are displayed, you need to connect the display form and control, here you need to pass the iVideoWindow interface method, VideoWindow. Put_owner (edit1.handle);
VideoWindow. Put_windowstyle (dsvideo_window_child_style);
VideoDow.SetWindowPosition (0, 20, Edit1.ClientWidth, Edit1.ClientHeight);
Get some of the necessary information of the image, use the method in the ibasicVideo interface, some variables you define yourself.
BasicVideo.getvideSize (VideoWidth, VideoHEOHT);
BasicVideo.get_bitrate (videobitch);
BasicVideo.get_avgtimeperframe (perframe);
Get the total time and play time of the current file, you need to use the iMediaseEKing interface method,
MediaseEKing.getduration (DURATION); // Get total time
MediaseEKing.getCurrentPosition (currentpos); // Get the current play time
You can also set the start and end time via the iMediaseEKing :: setPositions method.
Oh, the unit you get here seems to be millimeters, you can convert yourself into seconds.
Also, if you want a single frame to control playback, you also need to set the play format to play with frame.
MediaseEKing.SetTimeFormat (Time_Format_frame);
Play, stop, pause, etc.
These needs to use the iMediaControl interface, which is simple, respectively,
MediaControl.play;
MediaControl.stop;
MediaControl.pause;
Last continued