【问题标题】:How to Show Preview in PictureBox?如何在 PictureBox 中显示预览?
【发布时间】:2012-06-19 20:03:03
【问题描述】:

我也使用 DirectshowLib 和 c# 从网络摄像头录制视频,但在视频重新编码期间,视频预览也会显示,因此我已完成以下步骤

1.我有可用的视频设备

  1. 初始化。 IFilterGrapth2 对象使用Graph = (IFilterGraph2)new FilterGraph();

  2. 初始化。 ICaptureGraphBuilder2 对象使用captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

4.filter graphth设置为ICaptureGraphBuilder2对象captureGraph.SetFiltergraph(Graph);

  1. 然后添加了soursefilterformoniker()和outputfilename()

完整代码如下。它没有任何错误,但它单独打开预览窗口;我想在图片框上显示预览..

如何在图片框中预览窗口?

这是我的完整代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DirectShowLib;
using DirectShowLib.DMO;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
using System.IO;

namespace Cam_Recording_V1_directshow.net_
{
    public partial class Form1 : Form
    {
        string captureDeviceName = string.Empty;
        IFilterGraph2 Graph = null;
        IMediaControl m_mediaCtrl = null;
        public List<DsDevice> AvailableVideoInputDevices { get; private set; }
        IAMVideoProcAmp vpa;
        [DllImport("olepro32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        private static extern int OleCreatePropertyFrame(IntPtr hwndOwner, int x, int y,
            string lpszCaption, int cObjects,
            [In, MarshalAs(UnmanagedType.Interface)] ref object ppUnk,
            int cPages, IntPtr pPageClsID, int lcid, int dwReserved, IntPtr pvReserved);
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            IBaseFilter capFilter = null;
            IBaseFilter asfWriter = null;
            IFileSinkFilter pTmpSink = null;
            ICaptureGraphBuilder2 captureGraph = null;
            object o;

            //
            //Get list of video devices
            //
            AvailableVideoInputDevices = new List<DsDevice>();
            DsDevice[] videoInputDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            AvailableVideoInputDevices.AddRange(videoInputDevices);
            if (AvailableVideoInputDevices.Count > 0)
            {
                //
                //init capture graph
                //
                Graph = (IFilterGraph2)new FilterGraph();
                captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

                //
                //sets filter object from graph
                //
                captureGraph.SetFiltergraph(Graph);
                //
                //which device will use graph setting
                //
                Graph.AddSourceFilterForMoniker(AvailableVideoInputDevices.First().Mon, null, AvailableVideoInputDevices.First().Name, out capFilter);
                captureDeviceName = AvailableVideoInputDevices.First().Name;
                #region WMV
                //
                //sets output file name,and file type
                //
                captureGraph.SetOutputFileName(MediaSubType.Asf, /*DateTime.Now.Ticks.ToString()  +".wmv"*/ "test.wmv", out asfWriter, out pTmpSink);
                //
                //configure which video setting is used by graph
                //                
                IConfigAsfWriter lConfig = asfWriter as IConfigAsfWriter;
                Guid cat = new Guid("8C45B4C7-4AEB-4f78-A5EC-88420B9DADEF");
                lConfig.ConfigureFilterUsingProfileGuid(cat);
                #endregion                      
                captureGraph.RenderStream(PinCategory.Preview, MediaType.Video, capFilter, null, null);

                captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, null, asfWriter);
                m_mediaCtrl = Graph as IMediaControl;
                m_mediaCtrl.Run();
            }
            else
            {
                MessageBox.Show("Video Capture Device Not Found!!");
                button1.Visible = false;
            }
        }

【问题讨论】:

    标签: c# directshow.net


    【解决方案1】:

    我已经使用 VMR9 完成了这项工作。我在图表中添加了一个 VMR9 过滤器。还有更多。

    【讨论】:

    • 您能否详细说明一下您是如何实际连接 Image 和 VMR9 滤镜的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 2021-11-27
    • 1970-01-01
    相关资源
    最近更新 更多