|
XNA 2.0 made some "breaking changes" from XNA 1.0 that impact this code. Thanks to Odinlai for bringing this issue to my attention. To use this code with XNA Framework 2.0 change references to Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game from version 1.0 to 2.0 and make the following changes in the code files:
In VideoComponent.cs
FROM (248): private void LoadContent()
TO (248): protected override void LoadContent()
In VideoTexture.cs
FROM (155): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, ResourceUsage.None, SurfaceFormat.Color, ResourceManagementMode.Automatic);
TO (155): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);
FROM (190): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, ResourceUsage.None, SurfaceFormat.Color, ResourceManagementMode.Automatic);
TO (190): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);
INSERT BETWEEN (618-619): this.graphics.Textures[0] = null; // Workaround suggested in https://connect.microsoft.com/feedback/Workaround.aspx?FeedbackID=318195&SiteID=226
In xnaVideoViewer.cs
INSERT BETWEEN (96-97): [Obsolete]
INSERT BETWEEN (115-116): [Obsolete]
The next update to this site will include these changes. In the meantime, please make the changes manually if you are affected by this issue.
Thanks.
Steve.
|
|
|
|
|
when i compile the VideoTexture.cs
an error occur:
Error 1 The name 'ResourceUsage' does not exist in the current context D:\fun project\webcam with xna\webcam with xna\VideoTexture.cs 155 92 webcam with xna
is my setting is wrong??
please help
|
|
|
|
|
Thanks for bringing this error to my attention.
Unfortunately, ResourceUsage has been removed from XNA Framework 2.0, creating a breaking change from XNA Framework 1.0. Methods that used to take ResourceUsage now take BufferUsage or TextureUsage. The Texture2D constructor in particular now requires a TextureUsage. This is also a breaking change from XNA Framework 1.0.
The easiest way to make the software work is to reference the Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game libraries for Version 1.0. I realize that this is unsatisfactory for anyone using the 2.0 frameworks (which I would prefer to use myself...)
I have made the changes necessary to compile the program under XNA 2.0. This required changing the following lines:
FROM:
this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, ResourceUsage.None, SurfaceFormat.Color, ResourceManagementMode.Automatic);//Version 1.0
TO:
this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);// Version 2.0
A few warnings are now generated about obsolete methods, and these should also be corrected.
Although this compiles without error, the following line now generates a runtime framework error:
this.videoTexture2D.SetData<Microsoft.Xna.Framework.Graphics.Color>(colorData);
The error is:
"A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll"
This error can be thrown if the number of elements in the array colordata is not the same as the size of the Texture2D (it is), or if the Texture2D resource is currently set on the graphics device (maybe it is.) This looks like it is also an (undocumented) breaking change from XNA 1.0. I am afraid that more work will be needed to resolve this problem...
Steve.
|
|
|
|
|
I have been able to confirm this bug in the XNA 2.0 framework. Fortunately there is a workaround:
Change the VideoTexture.BufferCB() method to the following:
/// <summary>
/// Buffer Callback method from the DirectShow.NET ISampleGrabberCB interface. This method is called
/// when a new frame is grabbed by the SampleGrabber.
/// </summary>
/// <param name="SampleTime">The sample time.</param>
/// <param name="pBuffer">A pointer to the image buffer that contains the grabbed sample.</param>
/// <param name="BufferLen">The length of the image buffer containing the grabbed sample.</param>
/// <returns>0 = success.</returns>
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
byte[] bgrData = new byte[BufferLen];
Marshal.Copy(pBuffer, bgrData, 0, BufferLen);
Color[] colorData = new Color[BufferLen / 3];
for (int i = 0; i < colorData.Length; i++)
{
colorData[i] = new Microsoft.Xna.Framework.Graphics.Color(bgrData[3 * i + 2], bgrData[3 * i + 1], bgrData[3 * i]);
}
// The following line works in XNA 1.0 but generates an error in XNA 2.0
this.graphics.Textures[0] = null; // Workaround suggested in https://connect.microsoft.com/feedback/Workaround.aspx?FeedbackID=318195&SiteID=226
this.videoTexture2D.SetData<Microsoft.Xna.Framework.Graphics.Color>(colorData);
RaiseNewVideoTextureEvent(); // notify subscribers, if any.
return 0;
}
This should allow the code to operate correctly under XNA 2.0.
Steve.
|
|
|
|
|
I can't create two video components to play two different videos simultaneously.
|
|
|
|
|
Hi Lars;
For some unknown reason Codeproject is not allowing me to reply to your post today, hence this new post.
The size of the texture is set by inspecting the size of the source video. If you want to have a larger texture then you will need to change the output size from your webcam, if you webcam allows it.
Steve.
-- modified at 12:34 Thursday 11th October, 2007
|
|
|
|
|
This is really a nice little class.
Unfortuantely it only grabs pictures sized 320*240 on my Pc. Could you tell me how I could increase the resolution?
Greetings Lars
|
|
|
|
|
In order to integrate in my current project i have added Videotexture and videocomponent classes and referenced direcshowlib.
It compiles well.
I have added
TV = new VideoComponent(this);
this.Components.Add(TV);
in initialize method of game1.cs
and
TV.VideoTexture.Start(); (ive tried TV.VideoTexture.Run() also)
in the game1 update method
it compiles but is not showing anything.
(i am using a public static spritebatch declared in game1 in the video componet class not the videosprite spritebatch declared in videocomponent.
|
|
|
|
|
There are some arguments of wrong type
What version of directxlib should i use?
The binaries (xnaviewer.exe) does not work, it crashes too.The two dlls are in the same folder that the .exe.
I am trying to play an .avi there is no webcam installed. The final goal of the prject is play video from a TV card.
directxlib used:
v 2.0 - (2007-07-15)
Errors (in spanish sorry )
--------------------------------------------------------------
Error 4 La mejor coincidencia de método sobrecargado para 'DirectShowLib.IMediaEventEx.FreeEventParams(DirectShowLib.EventCode, System.IntPtr, System.IntPtr)' tiene algunos argumentos no válidos C:\Documents and Settings\XnaVideoProjectFiles\xnaVideoProjectFiles\xnaVideoLib\VideoTexture.cs 595 26 xnaVideoLibary
Error 2 Argumento '2': no se puede convertir de 'out int' a 'out System.IntPtr' C:\Documents and Settings\XnaVideoProjectFiles\xnaVideoProjectFiles\xnaVideoLib\VideoTexture.cs 570 70 xnaVideoLibary
Error 3 Argumento '3': no se puede convertir de 'out int' a 'out System.IntPtr' C:\Documents and Settings\XnaVideoProjectFiles\xnaVideoProjectFiles\xnaVideoLib\VideoTexture.cs 570 87 xnaVideoLibary
Error 4 La mejor coincidencia de método sobrecargado para 'DirectShowLib.IMediaEventEx.FreeEventParams(DirectShowLib.EventCode, System.IntPtr, System.IntPtr)' tiene algunos argumentos no válidos C:\Documents and Settings\XnaVideoProjectFiles\xnaVideoProjectFiles\xnaVideoLib\VideoTexture.cs 595 26 xnaVideoLibary
Error 5 Argumento '2': no se puede convertir de 'int' a 'System.IntPtr' C:\Documents and Settings\XnaVideoProjectFiles\xnaVideoProjectFiles\xnaVideoLib\VideoTexture.cs 595 71 xnaVideoLibary
Error 6 Argumento '3': no se puede convertir de 'int' a 'System.IntPtr' C:\Documents and Settings\XnaVideoProjectFiles\xnaVideoProjectFiles\xnaVideoLib\VideoTexture.cs 595 84 xnaVideoLibary
|
|
|
|
|
Answering myself :
//int eventParam1, eventParam2;
IntPtr eventParam1, eventParam2
------------------------------------------------------------
Now another question. I I connect a tv receiver card can i use yourcomponent to play video from it?
|
|
|
|
|
Answering myself again.
Yes it works
|
|
|
|
|
Hi Stephen
I posted many requests for several forums to get a component for streaming video in network.
I developed a software for a medical clinics. Doctors like to see Waiting Room.
My software installed in two computers. One in clerck's room and another in doctor's room and they work together. I connected webcam to clerck's computer and i want to send video to doctor's computer.
Is your code can help me about this. before i used MediaEncoder that it has delay and its not usefull.
Tanx
|
|
|
|
|
The VideoTexture class is not directly usable by a remote object because it is not a MarshalByRef object, and it depends upon a GraphicsDevice object that binds it to a specific context.
However, the source could be worked fairly easily into a remotable object that would, for example, pass width, height, and an array of colorData through an EventArg using a Client-Server model. The client could update a VideoTexture object using these arguments.
This sounds like a worthy extension, and I may do it if I have time. Unfortunately, I will be travelling for the next month and will not be able to consider it until I return in mid October.
Steve.
|
|
|
|
|
Hi mister,
any solution about it ? some code source please ?
Regards
AE
|
|
|
|
|
Esto no tira ni empujando
One word witch two different miniuns funy ingles
|
|
|
|
|
Me disculpo por mi español pobre. Si entiendo tu comentario, no puedes recibir el NewVideoTextureEvent cuando suscribes. ¿Es este correcto? ¿Se levanta una excepción?
|
|
|
|
|
Is it possible to play a movie file with voice synchronously in XNA?
|
|
|
|
|
I am sure that it can be done; however this project has not attempted to work with the audio tracks of the video files, which are simply ignored by the DirectShow filter graphs that I am using. If you use XACT to pull your sound files into the XNA project, then you would have to try to synchronize the audio and video yourself, I am afraid.
Steve.
|
|
|
|
|
Yes XACT could be used as an alternative but it would be great to use direct show to play the movie with audio anyway...
|
|
|
|
|
Hi,
I can't set the destination rectangle for Texture2D. Actualy the scene does not fit in the textures scale and also by default VideoTexture2D are rotated by 90 degrees. I have tested the component with a mpeg file.
Thanx for the great job though
|
|
|
|
|
Hi;
The VideoTexture2D and the Texture2D classes do not expose source or destination rectangles as such. However, if I understand your question correctly, you are asking about setting the destination rectangle for the sprite that is rendered by the Draw() call in the VideoComponent class. To do this, you can set the DestinationRectangle property of the VideoComponent, and this will change where the sprite is drawn on the screen. By changing the SourceRectangle property of the VideoComponent you can select a sub-region of the source video to display, which can change the apparent scaling. Different choices of source and destination rectangles will obviously change the scaling and appearance of the video as it is rendered on the sprite. Similiarly, you can change the SpriteFlip property of the VideoComponent class to ensure that the video is rotated and flipped properly for you. Hope this helps.
Steve.
|
|
|
|
|
|
when i try to open the project demo I had this error message :"....cannot open this project. the porject type is not supported by this installation" ( PC configuration: Windows XP, MS visual studio 2005 version 8 and framwork version2)
Thanks a lot
|
|
|
|
|
Hi!
This project is a Microsoft XNA Game Studio Express project, which uses the XNA library and is intended to be used within the Microsoft Visual Studio Express C# environment (a free download that is well worth checking out!). XNA is Microsoft's new game development software that allows a programmer to write games that will work on both the PC and the XBox 360. For reasons of their own, they have decided to only support XNA on the Express Version of Visual Studio, and so there are some differences in the project and solution files that make them incompatible with Visual Studio 2005 Professional, for example. This is not an insurmountable problem, and there are ways to make this project work just fine within Visual Studio 2005 Professional; however, I would encourage you to go ahead and download the Express version and XNA and use it the way Microsoft built it to be used. People are building amazing games with this technology, just using the free downloads. I have the full blown version of Visual Studio 2005 with all the bells and whistles myself, and I am using XNA within it. However, this project is build just using the free tools, for other developers who are using them as well.
To find out all about XNA, and to get links to all the necessary downloads, you can check out: http://creators.xna.com/[^]
Cheers!
|
|
|
|
|
Hello,
A few hours ago I got a xnaVideoLibrary ( http://www.codeproject.com/csharp/VidTextureClassWebcamApp.asp ), added dlls, wrote some code and compiled as well.
Now, when I run I get my game crush. Debugger gives me this error:
An unhandled exception of type 'System.Exception' occurred in xnaVideoLibrary.dll
Additional information: Unable to Load Webcam Component.
Any ideas?
|
|
|
|
|