The AsfWriter Filter

 

The AsfWriter

If we drop an ASFWriter, from DSPack, onto our form we can look at its important properties in Delphi's Object Inspector...

The AsfWriter is automatically assigned the network IP address if one is present. If the computer is part of a LAN, then the AsfWriter will assign itself the computer's LAN address. If the computer is connected directly to the internet, it will be assigned that address. The AsfWriter operates in "pull mode" - clients connect and pull the stream from the network encoder using the url: http://IP_address:port

Two networking properties that we can directly access from the Object Inspector are the maximum number of users we want to allow to connect at the same time (MaxUsers) and the network Port Number that we want to use (Port). Incidentally, setting MaxUsers to zero, disables the network streaming.

Different Port Numbers are defined internationally for different purposes. You can find an up to date list of Port Numbers here. As the AsfWriter uses the http protocol, use port 80 or 8080 if in doubt.

The two AsfWriter properties we are particularly interested in here are Profile and Filename.

Set the Profile as wmp_V80_56VideoOnly.

We can set the Filename in code. Declare a variable, OutputFile, as a Global variable and define it in the Form's FormCreate procedure. It doesn't matter what we call it so, for simplicity, here we'll just copy the project's path and filename - and change the filename extension to .asf - If you prefer, you can give it an absolute filename, such as 'c:\test\project1.asf' or add an OpenDialog and choose a Filename at runtime.

var
  Form1: TForm1;
  VideoDev: TSysDevEnum;
  OutputFile: String; 

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
    i: Integer;

begin
    VideoDev:= TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
    if VideoDev.CountFilters > 0 then
    begin
      for i:= 0 to VideoDev.CountFilters - 1 do
        ComboBox1.Items.Add(VideoDev.Filters[i].FriendlyName);
    end;

    OutputFile:= ChangeFileExt(ParamStr(0), '.asf');
end;

All we need to do now, is set the AsfWriter1.Filename property before we add it to the FilterGraph in the ComboBox1Select procedure. We should set the AsfWriter's FilterGraph property here as well - or we could just set it in the Object Inspector...

procedure TForm1.ComboBox1Select(Sender: TObject);
begin
   if FilterGraph1.Active then FilterGraph1.Active:= False;
   FilterGraph1.ClearGraph;

   Filter1.BaseFilter.Moniker:= VideoDev.GetMoniker(ComboBox1.ItemIndex);
   FilterGraph1.Active:= True;
   VideoWindow1.FilterGraph:= FilterGraph1;
   Filter1.FilterGraph:= FilterGraph1;
   FilterGraph1.Mode:= gmCapture;
  
   AsfWriter1.Filename:= OutputFile;
   AsfWriter1.FilterGraph:= FilterGraph1;

   with FilterGraph1 as ICaptureGraphBuilder2 do
   begin
      RenderStream(@PIN_CATEGORY_PREVIEW, nil, Filter1 as IBaseFilter,
                     nil, VideoWindow1 as IBaseFilter);

      RenderStream(@PIN_CATEGORY_CAPTURE , nil, Filter1 as IBaseFilter,
                     nil,  ASFWriter1 as IBaseFilter);
   end;
   FilterGraph1.Play;
end;

Here's how GraphEdit displays our Filter Graph. Note how the output pin from our Filter1 is connected to a 'Smart Tee' filter. It's Capture output pin 'connects' to the output file ( Project1.asf) and the Preview pin connects, through a Color Space Converter to our VideoWindow1.

Remember that, as soon as we select a video source (ComboBox1Select), we are streaming the video, in ASF format, onto our network but we are also writing the ASF file to our Hard Drive. On the next page, we'll look at how to prevent that file being written!

As a final part on this page, we may as well add a Button and a bit of code to stop the streaming....

procedure TForm1.Button1Click(Sender: TObject);
begin
   FilterGraph1.Stop;
   FilterGraph1.Active:= False;
   FilterGraph1.ClearGraph;
end;

previous page | next page

1 | 2 | 3 | 4 | 5 | 6 |


This site and its contents are © Copyright 2005 - All Rights Reserved.