本文介绍了DirectShow VB.net无法更改记录格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用直接表演来尝试将摄像头流捕获到我的vb.net程序中。以下是该子例程的运行方式:

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

但是当我更改行时:

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)

我出现黑屏并出现错误:

I get a black screen and an error:

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

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

谢谢

推荐答案

您需要先配置 WM ASF Writer ,然后才能使用 RenderStream 。请参见以获取详细信息。

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.

这篇关于DirectShow VB.net无法更改记录格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 21:03