从Webcam访问原始视频流 - DirectShow,C#

时间:2014-07-12 07:10:07

标签: c# video video-streaming webcam directshow.net

我正在尝试使用DirectShow.Net库构建视频会议桌面软件

我已经能够在本地预览面板上的实时素材。 现在我需要这个原始数据馈送通过网络。 对于noob问题很抱歉,但我无法确定如何访问此Feed。

到目前为止

代码:

public partial class Form1 : Form
{
private LiveJob job;
private LiveDeviceSource livedevicesource;
private bool startedrecording;

List<object> lstVideoDevices = new List<object>(10);
List<object> lstAudioDevices = new List<object>(10);

public Form1()
{
    InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

    foreach (EncoderDevice edv in EncoderDevices.FindDevices(EncoderDeviceType.Video)) {
        lstVideoDevices.Add(edv.Name);
        label1.Text=label1.Text+" "+ edv.Name;
    }
    foreach (EncoderDevice eda in EncoderDevices.FindDevices(EncoderDeviceType.Audio))
    {
        lstVideoDevices.Add(eda.Name);
        label2.Text = label2.Text + " " + eda.Name;
    }
}

private void btnStartPreview_Click(object sender, EventArgs e)
{
    EncoderDevice video = EncoderDevices.FindDevices(EncoderDeviceType.Video).ElementAt(1);
    EncoderDevice audio = EncoderDevices.FindDevices(EncoderDeviceType.Audio).ElementAt(0);

    if (video == null)
    {
        return;
    }

    job = new LiveJob();

    if (video != null && audio != null) {
        livedevicesource = job.AddDeviceSource(video, audio);
        livedevicesource.PickBestVideoFormat(new Size(640,480), 15);

        SourceProperties sourceprop = livedevicesource.SourcePropertiesSnapshot();
        pnlVideoUs.Size = new Size(sourceprop.Size.Width, sourceprop.Size.Height);

        //This line here sets panel as the preview window
        livedevicesource.PreviewWindow = new PreviewWindow(new HandleRef(pnlVideoUs, pnlVideoUs.Handle));
        job.ActivateSource(livedevicesource);   
    }
}

1 个答案:

答案 0 :(得分:0)

  

我需要这个原始数据Feed

查看DirectShow.NET附带的\Samples\Capture\DxLogo示例:

  

一个示例应用程序,显示如何在数据流上叠加徽标。它用   视频源的捕获设备,并将结果输出到文件。

尽管如此,该示例的主要目标略有不同,它可以访问原始视频数据:

int ISampleGrabberCB.BufferCB( double SampleTime, IntPtr pBuffer, int BufferLen )
{
  // ...
  CopyMemory(ipDest, ipSource, (uint)m_bmdLogo.Stride);