ImageEn, unit iemmf

TIEMediaFoundationSourceReader


Declaration

TIEMediaFoundationSourceReader = class;


Description

Encapsulates Microsoft Media Foundation source reader object, allowing the capture of video and audio samples from a source.

Presently TIEMediaFoundationSourceReader can capture from video capture devices (webcams), files (all formats supported by Windows Media Player) and URLs.

To setup TIEMediaFoundationSourceReader, applications must specify a video/file source, a video/audio stream and a media type. Then call GetNextSample() to read samples (images) from the source.
TImageEnView and TImageEnIO embed a TIEMediaFoundationSourceReader object to simplify usage.

TIEMediaFoundationSourceReader is available in Windows Vista and newer. We have tested to confirm compatibility with Windows 7, 8.1 and 10.




Overview




Demos

Demo  Demos\VideoCapture\MediaFoundationCam\MediaFoundationCam.dpr
Demo  Demos\VideoCapture\MediaFoundationFile\MediaFoundationFile.dpr
Demo  Demos\VideoCapture\MediaFoundationURL\MediaFoundationURL.dpr


Example

// This is a minimal setup to capture from a webcam (the first webcam, using first proposed media type):

ImageEnView1.IO.MediaFoundationSourceReader.SetVideoInput(0);                   // select first video input (first webcam)
ImageEnView1.IO.MediaFoundationSourceReader.SetSelectedStreams('Video', true);  // enable first video stream
ImageEnView1.IO.MediaFoundationSourceReader.SelectMediaType(mmf_VIDEO_STREAM, 0);        // select first media type of the first video stream
ImageEnView1.IO.MediaFoundationSourceReader.StartCapture();                     // start capture

// handler for TImageEnView.OnMediaFoundatioNotify event
procedure TForm1.ImageEnView1MediaFoundationNotify(Sender, MediaFoundationObject: TObject; NotifyType: TIEMediaFountationNotifyType);
var
  sample: TIEMFReceivedSample;
begin
  if NotifyType = iemfnFRAME then // is this a frame?
  begin
    sample := ImageEnView1.IO.MediaFoundationSourceReader.GetNextSample();  // retrieve frame sample
    try
      sample.DecodeSample(ImageEnView1.IEBitmap); // convert frame sample to bitmap
      ImageEnView1.Update();                      // update TImageEnView to show the new bitmap
    finally
      sample.Free();                              // free the sample
    end;
  end;
end;



Methods and Properties

Media Foundation Availability
Public Property  IsAvailable

Events/Frame Notification
Public Method  ClearNotifyReceivers
Public Method  PopNotifyReceiver
Public Method  PushNotifyReceiver

Video Input Information
Public Method  UpdateVideoInputs
Public Property  VideoInputs

Input Selection
Public Method  SetFileInput
Public Method  SetURLInput
Public Method  SetVideoInput

Stream Information
Public Method  GetStreamType
Public Method  IndexOfFirstStream
Public Property  StreamCount

Stream Selection
Public Method  SetSelectedStreams

Media Type Information
Public Method  GetMediaType
Public Method  GetMediaTypesCount

Media Type Selection (for native media type selection)
Public Method  SelectMediaType

Media Type Setting (for custom media types)
Public Method  SetMediaTypeAudio
Public Method  SetMediaTypeCustom
Public Method  SetMediaTypeVideo

Current Media Type Info
Public Method  GetCurrentMediaType

Seeking
Public Property  Duration
Public Method  SetPosition

Capture Control
Public Property  Capturing
Public Method  Flush
Public Method  PauseCapture
Public Method  ResumeCapture
Public Method  StartCapture
Public Method  StopCapture

Sample Capture
Public Method  GetNextSample
Public Property  SamplesBufferSize
Public Property  DiscardAudioSamples

Video Processing
Public Method  VideoProcessor