0

我正在使用直接显示尝试将网络摄像头流捕获到我的 vb.net 程序中。这是运行的子程序:

Private Sub CaptureVideo()
            Dim hr As Integer = 0
            Dim sourceFilter As IBaseFilter = Nothing
            Try
                GetInterfaces()

                hr = Me.CaptureGraphBuilder.SetFiltergraph(Me.GraphBuilder)
                Debug.WriteLine("Attach the filter graph to the capture graph : " & DsError.GetErrorText(hr))
                DsError.ThrowExceptionForHR(hr)

                sourceFilter = FindCaptureDevice()

                hr = Me.GraphBuilder.AddFilter(sourceFilter, "Video Capture")
                Debug.WriteLine("Add capture filter to our graph : " & DsError.GetErrorText(hr))
                DsError.ThrowExceptionForHR(hr)



                hr = Me.CaptureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, Nothing, Nothing)
                Debug.WriteLine("Render the preview pin on the video capture filter : " & DsError.GetErrorText(hr))
                DsError.ThrowExceptionForHR(hr)


                Dim pSink As DirectShowLib.IFileSinkFilter = Nothing
                Dim pMux As DirectShowLib.IBaseFilter = Nothing
                hr = Me.CaptureGraphBuilder.SetOutputFileName(DirectShowLib.MediaSubType.Avi, "c:\video\myvid1.avi", pMux, pSink)
                Debug.WriteLine("Set File : " & DirectShowLib.DsError.GetErrorText(hr))
                DirectShowLib.DsError.ThrowExceptionForHR(hr)


                hr = Me.CaptureGraphBuilder.RenderStream(DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, sourceFilter, Nothing, pMux)
                Debug.WriteLine("Render the capture pin on the video capture filter : " & DirectShowLib.DsError.GetErrorText(hr))
                DirectShowLib.DsError.ThrowExceptionForHR(hr)

                Marshal.ReleaseComObject(sourceFilter)

                SetupVideoWindow()

                rot = New DsROTEntry(Me.GraphBuilder)

                hr = Me.MediaControl.Run()
                Debug.WriteLine("Start previewing video data : " & DsError.GetErrorText(hr))
                DsError.ThrowExceptionForHR(hr)

                Me.CurrentState = PlayState.Running
                Debug.WriteLine("The currentstate : " & Me.CurrentState.ToString)

            Catch ex As Exception
                MessageBox.Show("An unrecoverable error has occurred.With error : " & ex.ToString)
            End Try
        End Sub

但是,当我换行时:

hr = Me.CaptureGraphBuilder.SetOutputFileName(DirectShowLib.MediaSubType.Avi, "c:\video\myvid1.avi", pMux, pSink)

hr = Me.CaptureGraphBuilder.SetOutputFileName(DirectShowLib.MediaSubType.Asf, "c:\video\myvid1.wmv", pMux, pSink)

我得到一个黑屏和一个错误:

在此处输入图像描述

基本上我试图用 wmv 而不是未压缩的 AVI 录制(像 DiVX / xvid 之类的也可以)

谢谢

4

1 回答 1

0

您需要先进行配置,然后才能尝试WM ASF Writer使用它来连接它。RenderStream有关详细信息,请参阅将视频捕获到 Windows 媒体文件

于 2012-04-16T10:24:37.583 回答