Directshow GMFBridge将多个剪辑保存到单个文件中

时间:2014-04-25 11:06:18

标签: vb.net directshow directshow.net

以下是我与GMFBridge一起使用的主要代码。我有一个sg(sourcegraph)和rg(rendergraph)对象,它将filtergraph,mediaseeking等保存在一个地方,这样我就可以释放它们。

当我运行它时,它会完美地将剪辑渲染到屏幕上。寻找每个剪辑并正确播放。我在" Bridge End of Segment"中获得了正确的事件代码序列。我期望(即每个剪辑一个BEOS消息)。

但是,当我尝试将剪辑写入AVI文件时,我只获得第一个剪辑。我也只得到一个" Bridge End of Segment"信息。在"中使用rg"注释掉的代码section是我用来写入AVI文件的。如果我检查GraphEdit中的图形,它们是否正确连接。

我还添加了" Bridge End of Segment"底部的消息。

这让我发疯了。我必须遗漏一些非常简单的东西。任何帮助赞赏。

        ' Get the source media file...
        If openfile.ShowDialog = Windows.Forms.DialogResult.OK Then

            If Bridge Is Nothing Then
                Bridge = New GMFBridgeController
                Bridge.AddStream(True, eFormatType.eAny, True)
                'Bridge.AddStream(False, eFormatType.eMuxInputs, False)
                Bridge.SetBufferMinimum(200)
            End If

            With sg
                ' Create graph to use. 
                .graph = New FilterGraph

                ' Create other interfaces. Don't need them all but am 
                ' experimenting. 
                .mediacontrol = DirectCast(.graph, IMediaControl)
                .mediaseeking = DirectCast(sg.graph, IMediaSeeking)
                .mediaeventex = DirectCast(.graph, IMediaEventEx)
                .mediaeventex.SetNotifyWindow(Me.Handle, WM_GRAPHNOTIFY, Nothing)

                ' Create the graphedit entry so I can see what I've made. 
                .rotentry = New DsROTEntry(.graph)

                ' If not using bridge comment out this line. 
                sg.filter = Bridge.CreateSourceGraph(openfile.FileName, sg.graph)
            End With

            With rg
                .graph = DirectCast(New FilterGraph, IFilterGraph2)
                .capgraph = New CaptureGraphBuilder2
                .capgraph.SetFiltergraph(.graph)

                ''''' CODE THAT I USE TO WRITE TO AN AVI FILE
                '''''Dim aviDest As IBaseFilter = New AviDest()
                '''''.graph.AddFilter(aviDest, "AVI Mux")
                '''''Dim writer As IBaseFilter = New FileWriter
                '''''.graph.AddFilter(writer, "File Writer")
                '''''Dim filewriter As IFileSinkFilter2 = DirectCast(writer, IFileSinkFilter2)
                '''''filewriter.SetFileName(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\StatsManager\Videos\momtest.avi", Nothing)

                ' Create the render graph ...
                .filter = Bridge.CreateRenderGraph(sg.filter, .graph)

                ' Ancillary control interfaces...
                .mediaseeking = DirectCast(.graph, IMediaSeeking)
                .mediacontrol = DirectCast(.graph, IMediaControl)

                ' Let me see the graph in GraphEdit.
                .rotentry = New DsROTEntry(.graph)
            End With

            ' Add my list of offsets...
            For Each obj As Object In listOffsets.Items
                clipoffsets.Add(Val(obj.ToString))
            Next

            ' How long to play the clips for...
            clipplaytime = Val(txtClipTime.Text)

            ' Just so I know what video I chose. 
            Me.Text = "Video:" + Path.GetFileName(openfile.FileName)
        End If

这是处理"段末尾的代码"消息.....

Public Sub Bridge_OnEndOfSegment() Handles Bridge.OnEndOfSegment
    Try
        log("BEOS")
        clipindex = clipindex + 1
        If clipindex = clipoffsets.Count Then          ' this is the proper version :)
            log("End of clips")
            clipindex = 0
            If chkLoop.Checked = False Then
                sg.mediacontrol.Stop()
                rg.mediacontrol.Stop()
            Else
                log("....looping")
                SeekToClip(clipoffsets(clipindex))
            End If
        Else
            log("Moving to clip:" + clipoffsets(clipindex).ToString)
            SeekToClip(clipoffsets(clipindex))
        End If

    Catch ex As Exception
        log("ERROR in EOS :" + ex.Message)
    End Try
End Sub

0 个答案:

没有答案