解决方案 »

  1.   


    procedure Tfrmmain.StartRecord;
      var multiplexer: IBaseFilter;
          Writer: IFileSinkFilter;
          pGS : IAMGraphStreams;
          pConfigMux : IConfigAviMux;
    begin
      FRecordTime := 0;
      FRecordFile := FSaveFolder + FCombineFile;
      CaptureGraph.Stop;
      VideoCompress.FilterGraph := CaptureGraph;
      AudioCompress.FilterGraph := CaptureGraph;
      CaptureGraph.Active := true;  //音频视频同步
      if CaptureGraph.QueryInterface(IID_IAMGraphStreams, pGS) = 0 then
      begin
        pGS.SyncUsingStreamOffset(TRUE);
        pGS := nil;
      end;
      IF CaptureGraph.QueryInterface(IID_IConfigAviMux,pConfigMux) = 0 then
      begin
        pConfigMux.SetMasterStream(1);
        pConfigMux := nil;
      end;
      with CaptureGraph as IcaptureGraphBuilder2 do
      begin 
        SetOutputFileName(MEDIASUBTYPE_Avi, PWideChar(FRecordFile), multiplexer, Writer);
        if VideoSourceFilter.BaseFilter.DataLength > 0 then
          RenderStream(@PIN_CATEGORY_PREVIEW, @MEDIATYPE_Video, VideoSourceFilter as IBaseFilter, nil , RecordWindow as IBaseFilter);
        RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter,  VideoCompress as IBaseFilter, multiplexer as IBaseFilter);
        RenderStream(nil, nil, AudioSourceFilter as IBaseFilter,  AudioCompress as IBaseFilter, multiplexer as IBaseFilter);
      end;
      CaptureGraph.Play;
      GBeginRecord := True;
      tmrcount.Enabled := True;
    end;
      

  2.   

    兄弟,先谢谢你,请问VideoCompress和AudioCompress是什么控件?
      

  3.   

    不用压缩,改为NIL 
    RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter,  nil, multiplexer as IBaseFilter);
    RenderStream(nil, nil, AudioSourceFilter as IBaseFilter,  nil, multiplexer as IBaseFilter);
      

  4.   

    改了也是问题依旧,视频快于音频,我把代码贴一下。兄弟,能加一下Q最好了。
    procedure TMainForm.StartButtonClick(Sender: TObject);
    var
      multiplexer: IBaseFilter;
      Writer: IFileSinkFilter;
      PinList: TPinList;
      i: integer;
      pGS: IAMGraphStreams;
      pConfigMux: IConfigAviMux;
    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;  // 音频视频同步
      if CaptureGraph.QueryInterface(IID_IAMGraphStreams, pGS) = 0 then
      begin
        pGS.SyncUsingStreamOffset(true);
        pGS := nil;
      end;
      IF CaptureGraph.QueryInterface(IID_IConfigAviMux, pConfigMux) = 0 then
      begin
        pConfigMux.SetMasterStream(1);
        pConfigMux := nil;
      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,
            nil, 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;
      

  5.   

    能把你demo发给我一下吗,我qq 120911940
      

  6.   

    谢谢,收到你的demo了,在我机器上还是不同步的。你是用的dspack哪个版本。先把分给你,
      

  7.   

    这里有 http://download.csdn.net/detail/guanlianan/7043121
      

  8.   

    这里有DSPACK FOR XE3 ,刚刚我在电脑上也装了,运行DEMO的录像功能,视频和音频一切正常……
    唯一不正常的是——录制的AVI实在太大了
     http://download.csdn.net/detail/guanlianan/7043121