2012-04-13 78 views
0

我正在使用直接顯示嘗試捕捉到我的vb.net程序中的攝像頭流。繼承人的子程序運行的工作原理:當我改變行DirectShow 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) 

我得到一個黑色的屏幕和一個錯誤:

enter image description here

基本上我試圖WMV,而不是壓縮的AVI記錄(的東西,例如DivX/XVID將被罰款太)

感謝

回答

0

您需要配置WM ASF Writer之前,您可以在使用RenderStream,你試圖連接。有關詳細信息,請參見Capturing Video to a Windows Media File

+0

我以爲我已經這樣做了,我已經閱讀過這個鏈接(謝謝),但是我不是很瞭解它,有沒有什麼指針可以給我? – TMB87 2012-04-16 10:47:39

+0

注意它在那裏建議「有關設置配置文件的更多信息,請參閱在DirectShow中創建ASF文件。」用鏈接http://msdn.microsoft.com/en-us/library/windows/desktop/dd375008%28v=vs.85%29.aspx它意味着在'SetOutputFileName'之後但在'RenderStream'之前,你應該調用' IConfigAsfWriter :: ConfigureFilterUsingProfile' http://msdn.microsoft.com/en-us/library/windows/desktop/dd312023%28v=vs.85%29.aspx爲了配置您新添加的ASF書寫器。例如,如果您只捕捉視頻,則應該應用純視頻個人資料。 – 2012-04-16 11:03:36