我写一程序,要自已获得摄像头的图像,再一幅幅播出去,之所以要这样子做是因为要对获得的图像做些处理再形成视频。搜索网上的一些源码,程序基本能实现,但有一问题,它总要生成一个avi文件,这是我不需要的,而且占硬盘,有什么方法可以去掉。下面是部分代码。请高人指点,谢谢。

解决方案 »

  1.   

    procedure TMainForm.StartButtonClick(Sender: TObject);
    var
      multiplexer: IBaseFilter;
      Writer: IFileSinkFilter;
      PinList: TPinList;
      i: integer;
    begin  // Activate the filter graph, at this stage the source filters are added to the graph
      CaptureGraph.Active := true;  // configure output Audio media type + source
      if AudioSourceFilter.FilterGraph <> nil then
      begin
        PinList := TPinList.Create(AudioSourceFilter as IBaseFilter);
        i := 0;
        while i < PinList.Count do
          if PinList.PinInfo[i].dir = PINDIR_OUTPUT then
            begin
              if AudioFormats.ItemIndex <> -1 then
                with (PinList.Items[i] as IAMStreamConfig) do
                  SetFormat(AudioMediaTypes.Items[AudioFormats.ItemIndex].AMMediaType^);
              PinList.Delete(i);
            end else inc(i);
        if InputLines.ItemIndex <> -1 then
          with (PinList.Items[InputLines.ItemIndex] as IAMAudioInputMixer) do
            put_Enable(true);
        PinList.Free;
      end;  // configure output Video media type
      if VideoSourceFilter.FilterGraph <> nil then
      begin
        PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
        if VideoFormats.ItemIndex <> -1 then
          with (PinList.First as IAMStreamConfig) do
            SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^);
        PinList.Free;
      end;
      // now render streams
      with CaptureGraph as IcaptureGraphBuilder2 do
      begin
        // set the output filename
        SetOutputFileName(MEDIASUBTYPE_Avi, PWideChar(CapFile), multiplexer, Writer);    // Connect Video preview (VideoWindow)
        if VideoSourceFilter.BaseFilter.DataLength > 0 then
          //RenderStream(@PIN_CATEGORY_PREVIEW, nil, VideoSourceFilter as IBaseFilter,
          //  nil , VideoWindow as IBaseFilter);    // Connect Video capture streams
        if VideoSourceFilter.FilterGraph <> nil then
          RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter,
            samplegrabber1 as IBaseFilter, multiplexer as IBaseFilter);    // Connect Audio capture streams
        if AudioSourceFilter.FilterGraph <> nil then
        begin      RenderStream(nil, nil, AudioSourceFilter as IBaseFilter,
            nil, multiplexer as IBaseFilter);
        end;
      end;
      CaptureGraph.Play;
      StopButton.Enabled := true;
      StartButton.Enabled := false;
      AudioFormats.Enabled := false;
      AudioCapFilters.Enabled := false;
      VideoFormats.Enabled := false;
      VideoCapFilters.Enabled := false;
      //Timer.Enabled := true;
    end;
    ============================================================
    然后用一循环,通过 samplegrabber1.GetBitmap(bitmap);来获得每帧图片
      

  2.   

    DSPack 这东西我做了个 ydcap ,好像不用生成avi啊