0

I'm using direct show to try and capture a webcam stream in to my vb.net program. Heres the subroutine running which works:

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

However when I change the line:

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

to

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

I get a black screen and an error:

enter image description here

Basically i'm trying to record in wmv instead of uncompressed AVI (something like DiVX / xvid would be fine too)

Thanks

Roman R.
  • 68,205
  • 6
  • 94
  • 158
MissCoder87
  • 2,669
  • 10
  • 47
  • 82

1 Answers1

0

You need to configure WM ASF Writer before you can connect it using RenderStream as you attempt. See Capturing Video to a Windows Media File for details.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • I thought I was doing that already, I've read that link (thanks for that) but I don't really understand it, is there any pointers you can give me? – MissCoder87 Apr 16 '12 at 10:47
  • Note it suggests there "For more information about setting the profile, see Creating ASF Files in DirectShow." with a link http://msdn.microsoft.com/en-us/library/windows/desktop/dd375008%28v=vs.85%29.aspx It means that after `SetOutputFileName` but before `RenderStream` you should call `IConfigAsfWriter::ConfigureFilterUsingProfile` http://msdn.microsoft.com/en-us/library/windows/desktop/dd312023%28v=vs.85%29.aspx in order to configure your newly added ASF writer. For instance, if you only capture video, you should apply video-only profile. – Roman R. Apr 16 '12 at 11:03