2 videos with DirectShow in c# - c#

I would like to have 2 video windows playing a (same file for now) video. As I'm still new to c# and DirectShow I'm having problems with this and haven't found any working examples for multi-video solutions. I can get it to work for 1 window from samples, and would like to know what else is required to get the 2nd window working. Do I need to create a separate filter for the 2nd one aswell, or just fiddling around with the handles is enough?

What problems are you facing for multi-video rendering ?
As far as I know, you need to create one graph per video stream you want to have rendered, i.e. one Source/(Transform)/Render chain per stream. I don't think using a single render filter and playing with the windows handles is going to work (but I may be mistaken).
If you need to play the same video file in two different windows, just connect a Smart Tee filter after your source filter (or after your decompression filters), and connect a render filter to each of the Smart Tee's output pins.
If you want an easy method to test Directshow graphs, use GraphEdit (available in the DirectX SDK and in many other places on the Internet).

Related

C# directshow connect multiple graphs

I'm building a C# application where 2 or more cameras are connected to a processing module that has one or more outputs. I need to be able to connect "monitor" windows to preview each camera and the processed output that can be hidden or shown independently, with additional processing filters added to the stream while the video program is running.
Conceptually, I'm trying to build something that looks like this:
(source: fkeinternet.net)
(Using the Video Mixing Filter from the Video Processing Project, I can actually build the above graph and have it run with the three video renderers displaying their respective video streams - in ActiveMovie windows, not C# form windows. Building a graph is not exactly the problem, building the complete application is the issue.)
Building on example code from the DirectShow .NET project, combined with code generated by GraphEditPlus, I can build a basic application with the video stream from a single camera displayed in a C# form window. I'm in the process of debugging multiple preview windows operating simultaneously, but I've realized there are other issues:
One of the problems with the graph illustrated above is that if any of the output windows are closed, the whole graph stops. Another is that it doesn't allow adding filters in the processing stage without stopping the whole graph and rebuilding it.
My idea is to break the monolithic graph into separate source, processing and display graphs so that each piece can be started or stopped as needed, something like this:
(source: fkeinternet.net)
I'm assuming I'd have to keep one graph running all the time to provide a "master clock" source for everything else (probably the "Processing Graph" component), but I'm not quite sure how to do that.
Is there a "standard" way for connecting multiple graphs together? For that matter, is it even possible? I've done a number of searches along the lines of "c# directshow connect two graphs" but all of the links returned are related to connecting filters together, not graphs. Am I asking the wrong question?
I stumbled across this post which pointed me to the answer I was looking for - GMFBridge

Which one to use: DirectX? Windows Media Player? GNU? Others?

I want to create a windows Forms program where I play an AVI file.
I want to be able to play it in full speed, to pause, to get the total number of frames, and to show a given frame (seek).
The AVI file has metadata for the file AND metadata per frame.
I want to do this in a windows Forms application in C#, or if it is really necessary using C++.
Internet search shows me a lot of possibilities to use: DirectX, DirectShow, Windows Media Player, Microsoft DirectX9, GNU code, and several other methods.
Alas I haven't seen one that supports all that I want, especially the metadata per frame is not used often.
It seems that several of these methods are obsolete, for instance to be able to use Microsoft DirectX I need to add "useLegacyV2RuntimeActivationPolicy".
So anyone who knows what method is the latest and greatest method to use in windows programming? Which method allows me to show metadate-per-frame?

video call in c#

I want to make a similar application to Skype, and the main problem is working with video and audio. The first problem is how to get a bytes array of the video (to be specific, I need to get bytes which represent the video, so that I can send them over the internet), and same with audio. The second problem is to play bytes that come from the other computer.
I've been thinking to do that in WPF. I'm new in WPF (I have practiced a little bit, and made couple of programs among which is a basic chat program). I'm doing this for practice, and I want to code by myself as much as I can, server, client, transmision of data, and so on...
I've been searching over the internet, and only one solution seems to me to be good, or better to say feasible, is to use DirectShow.
Just to add, I know that camera and microphone is supported in Silverlight, and I've tried that (actually, I've tried to host an HTML page with silverlight project in WPF project in which were webbrowser control, and I've succeeded to show video from my webcam), but I don't know how to get bytes which represent video.
Is that possible to do with WPF or silverlight?
I'll be very grateful for suggesting any solution, advice, or useful links.
Using DirectShow filter graphs, you'll have a direct access to image and audio buffers from input devices (such as cameras and microphones) as bytes array, sample by sample. You'll be able to directly manipulate the data, to chose a coding or compression format (using specific filters), and to control the data rate and synchronization.
However :
if you've entirely new to this environment, it will be hard. Also, I know it works nicely with C++, but I've never coded any Directshow application in C#. (You may want to look this way : CodeProject Tutorials, MSDN DirectShow topics, and tests using graphedit)
streaming media accross a network and receiving it with Directshow is not trivial and can be quite a pain. Network renderers and network source filters are available all around, but are always difficult to use in my opinion. And depending on your video format (H264, MPEG, MJPEG...) and network protocol (RTSP, plain old simple UDP...) choices, you might end up having to write your own stream/source filters, which is hard and time consuming.
Nevertheless, it IS feasible, and if your main objective is practice with coding, then why not !
(Never used WPF, maybe it's actually way simpler !)
I can't speak to WPF or Silverlight, but I've done this in DirectShow, and it's a pain in the ass.
If you want to use .NET, there's an open source wrapper called DirectShow.NET, that helps alot, and it's still a pain in the ass.
Microsoft did a good job with DirectShow and the whole Filter-Graph thing, but then they sort of dropped the ball a while ago and haven't updated it in years.
I'd recommend looking for a different technology(although it probably sits on DirectShow), and I'd be interested to hear what you find.
To all who are interested in this subject,
After spending hours and hours searching the internet, i managed to find a solution that should work. With Silverlight i take captures, resizing them to 160x120 (or less), and than convert them with imagetools. One thread that is responsible for taking pictures, starts capture, and when it is finished (capturing is asynchronous, so you need semaphores to use) it sleeps for 200ms; thats almost equivalent to 5 frames per second. I'm doing all of this because i have slow upload bandwidth, about 16 kilobytes per second, so i have to compress one frame as much as i can. Result is low detailed picture, but if u use 100x100 rectangle for viewing it, it isn't too bad. I haven't tried it with the internet yet, but, as i have said, it should work. I've also tried using compress methods, to compress picture a little more, if it is possible, but i don't know how to use that class (something is not working well), so left that for another time. Now i just want to make it work, and latter i'll try to make better performance.
Oh, one more thing, I also have to solve problem with audio transmission, and that needs a lot of work.
So, hear latter.

how can i record audio in C#

I was wondering if there was a simple way to record audio, and have it saved as an object of any sort.
My personal goal is to eventually record audio, save it to a "channel", allow for multiple channels, and play them back simultaneously.
This project on CodeProject provides some classes for capturing audio. It uses Managed DirectX, which has been deprecated, so you might want to look into using SlimDx as a wrapper around DirectSound instead.
You could take a look into the OpenAL wrapper in OpenTK.
It should have what you need in it. The AudioCapture and AudioContext classes will collect your data, and then AL.SourcePlay() can be used to play multiple contexts together.

C# Video Playback

I'm looking at trying to create a simple 'slider puzzle' game. You've seen the ones, you have an image and you shuffle the tiles.
However, I want to make one that will play back videos instead. What I'm trying to determine is whether it's possible to playback a video in C# and render the video on different controls (probably buttons, or panels). I've spotted the Microsoft.DirectX.AudioVideoPlayback classes but haven't found much documentation on them yet.
So to throw it up in the air, is this going to be possible to do without too much difficulty? Are there any useful (free) libraries that might help me along?
Have a look at DirectShowNet that wraps the DirectShow API, in the samples page there is a sample called PlayWnd the shows how to play a video file.
Depending upon how large and how long your video sources are, you could accomplish this very simply by first converting your videos to animated GIFs. A .Net PictureBox control will display and animate a GIF automatically, and you could easily use PictureBoxes for your tiles.
One big advantage of this approach is that (thanks to Mono) your application could work unaltered on Windows, Mac and the iPhone (also Linux and a couple others).

Categories

Resources