Я могу воспроизводить живое видео, выбрав веб-камеру в качестве входного сигнала, используя прямое шоу. Ниже приведен код, который я использовал для этого.
Теперь вместо выбора устройства ввода видео, я хочу сделать снимок экрана как видео. Как я могу определить экран как основной фильтр? Пожалуйста, помогите предложить
private void buttonPlayVideoDevice_Click(object sender, EventArgs e)
{
if (comboBoxDevices.SelectedIndex < 0)
return;
StopPlaying();
Device device = (Device)comboBoxDevices.Items[comboBoxDevices.SelectedIndex];
if (m_player.OpenCamera(device, m_vcam_filter))
{
buttonStopVideoDevice.Enabled = true;
m_player.Run();
}
}
public bool OpenCamera(Device i_device, IBaseFilter i_vcam_filter)
{
// Stop and release interfaces
Cleanup();
bool succeeded = true;
IPin pin_out = null;
IPin pin_in = null;
int hr = 0;
// Create an instance of FilterGraph interface
m_graph_builder = (IGraphBuilder)new FilterGraph();
// Add camera source filter to our graph.
IBaseFilter filter_source = i_device.CreateDevice();
if (0 != (hr = m_graph_builder.AddFilter(filter_source, "Source Filter")))
{
succeeded = false;
goto exit;
}
// Add VCam Render filter to graph, the VCam Render will pass video frames to VCam
if (0 != (hr = m_graph_builder.AddFilter(i_vcam_filter, "VCam Renderer Filter")))
{
succeeded = false;
goto exit;
}
pin_out = DsFindPin.ByDirection(filter_source, PinDirection.Output, 0);
pin_in = DsFindPin.ByDirection(i_vcam_filter, PinDirection.Input, 0);
if (pin_out == null || pin_in == null)
{
succeeded = false;
goto exit;
}
if (0 != (hr = m_graph_builder.Connect(pin_out, pin_in)))
{
succeeded = false;
goto exit;
}
m_control = (IMediaControl)m_graph_builder;
exit:
if (filter_source != null) Marshal.ReleaseComObject(filter_source);
if (pin_out != null) Marshal.ReleaseComObject(pin_out);
if (pin_in != null) Marshal.ReleaseComObject(pin_in);
return succeeded;
}