Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to convert this graphfilter diagram in graph edit to c# code using directshow.lib graphbuilder?
http://www.omnivex.com/media/forums/capture/WinTV-PVR-150.png[^]

[Edit]Made you're able to click on the link[/Edit]
Posted
Updated 27-Oct-12 4:30am
v2

1 solution

Hello,

Here you just need to insert your capture source ("Hauppauge WinTV PVR PCI II Capture") into filter graph, then render it via ICaptureGraphBuilder2 from pin "656" using RenderStream. So the brief graph building will be looks:
C#
ICaptureGraphBuilder2 _builder;
IPin _output = FindPinByName("656"); 
_builder.RenderStream(null,null,_output,null,null);

Regards,
Maxim.
 
Share this answer
 
Comments
Jen123sml 3-Nov-12 6:23am    
can you give me an example of the full code for creating custom graph similar to the one I need?
I'm getting trouble to create the graph using directshow.lib
Maxim Kartavenkov 3-Nov-12 8:19am    
show me code and there you have trouble
Jen123sml 3-Nov-12 9:39am    
using System;
using System.Runtime.InteropServices;
using DirectShowLib;

namespace CaptureTest
{
internal class Capture : IDisposable
{

#region Member variables

// graph builder interface
private IFilterGraph2 m_FilterGraph = null;
IMediaControl m_mediaCtrl = null;

// Set by async routine when it captures an image
private bool m_bRunning = false;

#if DEBUG
DsROTEntry m_rot = null;
#endif

#endregion

/// release everything.
public void Dispose()
{
GC.SuppressFinalize(this);
CloseInterfaces();
}

~Capture()
{
Dispose();
}

///
/// Create capture object
///

/// <param name="iDeviceNum">Zero based index of capture device</param>
/// <param name="szFileName">Output ASF file name</param>
public Capture(int iDeviceNum, string szOutputFileName)
{
DsDevice[] capDevices;

// Get the collection of video devices
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

if (iDeviceNum + 1 > capDevices.Length)
{
throw new Exception("No video capture devices found at that index!");
}

try
{
// Set up the capture graph
SetupGraph(capDevices[iDeviceNum], szOutputFileName);

m_bRunning = false;
}
catch(Exception ex)
{
Dispose();
throw ex;
}
}


// Start the capture graph
public void Start()
{
if (!m_bRunning)
{
int hr = m_mediaCtrl.Run();
Marshal.ThrowExceptionForHR(hr);

m_bRunning = true;
}
}

// Pause the capture graph.
// Running the graph takes up a lot of resources. Pause it when it
// isn't needed.
public void Pause()
{
if (m_bRunning)
{
IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;

int hr = mediaCtrl.Pause();
Marshal.ThrowExceptionForHR(hr);

m_bRunning = false;
}
}

/// build the capture graph.
private void SetupGraph(DsDevice dev, string szOutputFileName)
{
int hr;

IBaseFilter capFilter = null;
IBaseFilter asfWriter = null;
ICaptureGraphBuilder2 capGraph = null;


// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2)new FilterGraph();

#if DEBUG
m_rot = new DsROTEntry(m_FilterGraph);
#endif

try
{
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

// Start building the graph
hr = capGraph.SetFiltergraph(m_FilterGraph);
Marshal.ThrowExceptionForHR(hr);

// Add the capture device to the graph


hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
Marshal.ThrowExceptionForHR(hr);

asfWriter = ConfigAsf(capGraph, szOutputFileName);


IPin _output = DsFindPin.ByName(capFilter, "656");
hr = capGraph.RenderStream(null, null, _output, null, null);

// hr = capGraph.RenderStream(null, null, capFilter, null, asfWriter);
Marshal.ThrowExceptionForHR(hr);

m_mediaCtrl = m_FilterGraph as IMediaControl;
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
Jen123sml 3-Nov-12 9:41am    
<pre> finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (asfWriter != null)
{
Marshal.ReleaseComObject(asfWriter);
asfWriter = null;
}
if (capGraph != null)
{
Marshal.ReleaseComObject(capGraph);
capGraph = null;
}
}
}

private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szOutputFileName)
{
IFileSinkFilter pTmpSink = null;
IBaseFilter asfWriter = null;

int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);
Marshal.ThrowExceptionForHR(hr);

try
{
IConfigAsfWriter lConfig = asfWriter as IConfigAsfWriter;

// Windows Media Video 8 for Dial-up Modem (No audio, 56 Kbps)
Guid cat = new Guid(0x6E2A6955, 0x81DF, 0x4943, 0xBA, 0x50, 0x68, 0xA9, 0x86, 0xA7, 0x08, 0xF6);

hr = lConfig.ConfigureFilterUsingProfileGuid(cat);
Marshal.ThrowExceptionForHR(hr);
}
finally
{
Marshal.ReleaseComObject(pTmpSink);
}

return asfWriter;
}</pre>
Maxim Kartavenkov 3-Nov-12 11:06am    
and what's the trouble?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900