我下了断代码 现在可以视频显示图像了, 我想把它进行传输
各位大侠帮我看看这个段代码应该在哪里修改
public void InitGraph()
{
if (theDevice == null)
return; object o; //Create the Graph
graphBuilder = (IGraphBuilder) new FilterGraph();
#if DEBUG
m_rot = new DsROTEntry(graphBuilder);
#endif //Create the Capture Graph Builder
ICaptureGraphBuilder2 captureGraphBuilder = null;
captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
//Create the media control for controlling the graph
mediaControl = (IMediaControl) this.graphBuilder; // Attach the filter graph to the capture graph
int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr); //Add the Video input device to the graph
hr = graphBuilder.AddFilter(theDevice, "source filter");
DsError.ThrowExceptionForHR(hr); //Add the Video compressor filter to the graph
if (theCompressor != null)
{
hr = graphBuilder.AddFilter(theCompressor, "compressor filter");
DsError.ThrowExceptionForHR(hr);
} //Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
IBaseFilter mux;
IFileSinkFilter sink;
hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, textBox1.Text, out mux, out sink);
DsError.ThrowExceptionForHR(hr); //Byte[] FileByteArray = new Byte[5000]; //图象文件临时储存Byte数组
//Stream StreamObject = DsError.ThrowExceptionForHR(hr); //建立数据流对像
////读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
//StreamObject.Read(FileByteArray, 0, 5000);
//Connect the device and compressor to the mux to render the capture part of the graph
hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, theDevice, theCompressor, mux);
DsError.ThrowExceptionForHR(hr); //Render any preview pin of the device
hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
DsError.ThrowExceptionForHR(hr); tuner = null;
crossbar = null; hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMTVTuner).GUID, out o);
if (hr >= 0)
{
tuner = (IAMTVTuner)o;
o = null; hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o);
if (hr >= 0)
{
crossbar = (IBaseFilter)o;
o = null;
}
}
//get the video window from the graph
IVideoWindow videoWindow = null;
videoWindow = (IVideoWindow) graphBuilder; //Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
hr = videoWindow.put_Owner(panel1.Handle);
DsError.ThrowExceptionForHR(hr); //Set the style of the video window
hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr); // Position video window in client rect of main application window
hr = videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
DsError.ThrowExceptionForHR(hr); // Make the video window visible
hr = videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr); Marshal.ReleaseComObject(mux);
Marshal.ReleaseComObject(sink);
Marshal.ReleaseComObject(captureGraphBuilder);
}
各位大侠帮我看看这个段代码应该在哪里修改
public void InitGraph()
{
if (theDevice == null)
return; object o; //Create the Graph
graphBuilder = (IGraphBuilder) new FilterGraph();
#if DEBUG
m_rot = new DsROTEntry(graphBuilder);
#endif //Create the Capture Graph Builder
ICaptureGraphBuilder2 captureGraphBuilder = null;
captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
//Create the media control for controlling the graph
mediaControl = (IMediaControl) this.graphBuilder; // Attach the filter graph to the capture graph
int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr); //Add the Video input device to the graph
hr = graphBuilder.AddFilter(theDevice, "source filter");
DsError.ThrowExceptionForHR(hr); //Add the Video compressor filter to the graph
if (theCompressor != null)
{
hr = graphBuilder.AddFilter(theCompressor, "compressor filter");
DsError.ThrowExceptionForHR(hr);
} //Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
IBaseFilter mux;
IFileSinkFilter sink;
hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, textBox1.Text, out mux, out sink);
DsError.ThrowExceptionForHR(hr); //Byte[] FileByteArray = new Byte[5000]; //图象文件临时储存Byte数组
//Stream StreamObject = DsError.ThrowExceptionForHR(hr); //建立数据流对像
////读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
//StreamObject.Read(FileByteArray, 0, 5000);
//Connect the device and compressor to the mux to render the capture part of the graph
hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, theDevice, theCompressor, mux);
DsError.ThrowExceptionForHR(hr); //Render any preview pin of the device
hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
DsError.ThrowExceptionForHR(hr); tuner = null;
crossbar = null; hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMTVTuner).GUID, out o);
if (hr >= 0)
{
tuner = (IAMTVTuner)o;
o = null; hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o);
if (hr >= 0)
{
crossbar = (IBaseFilter)o;
o = null;
}
}
//get the video window from the graph
IVideoWindow videoWindow = null;
videoWindow = (IVideoWindow) graphBuilder; //Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
hr = videoWindow.put_Owner(panel1.Handle);
DsError.ThrowExceptionForHR(hr); //Set the style of the video window
hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr); // Position video window in client rect of main application window
hr = videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
DsError.ThrowExceptionForHR(hr); // Make the video window visible
hr = videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr); Marshal.ReleaseComObject(mux);
Marshal.ReleaseComObject(sink);
Marshal.ReleaseComObject(captureGraphBuilder);
}
如果是这样的话你多了解一下H264编码 跟视频会议一样的
1、摄像头监控录像源代码 (详细的代码,可以直接使用,也可以拿来学习使用)
http://download.csdn.net/source/1172325
2、屏幕录像软件源代码 经典之作 分享
http://download.csdn.net/source/1387520/
3、C#摄像头编程代码
http://download.csdn.net/source/279427
socket 和DirectShow都行。
自定义一Transform Filter,把获取到的数据压缩后,写入到网络流中
我已经用Socket的TCP/IP方式进行编码, 但是我不知道在什么地方获取视频流,视频采集我用的是微软avicap32.dll动态库。 我查了它里面的所有函数,好像没有获取视频流的方法,你有这方面的资料吗?
AviCapture.SendMessage(this.lwndC, AviCapture.WM_CAP_SET_CALLBACK_FRAME, 0, FrameEventHandler);//注册帧回调函数这两个注册视频流 和帧的函数 我如果要使用,要怎么样才能使用?
FrameEventHandler,这个委托里,应该传了每一帧视频流数据吧,直接获取这个数据,写入到网络流不行吗?