Best image compression for C# - c#

I'm currently working on some software which captures your monitor image and sends it over to clients over the internet.
So far I have it working in my local area network but when I go to test it over the internet, hardly any of the images get through to the client.
I am using Lidgren for my networking. At the moment, I get a Bitmap from the screen, convert it to a JPEG with 30 quality, G-zip it and send it on its way. Each image is about 80KB in size, and I try to send 10 images a second to the client. Now that's like a 7mbit upload connection required, mines is only 2mbit.
So basically, is anyone aware of any compression libraries or techniques which will dramatically decrease the file size of each image. This might be completely impossible but I thought that I would give it a go.
Any help is much appreciated, Thanks!

Do you really need to send the whole frame each time? Could you not just send what has changed between the current and the previous frame and then apply these changes to the client frame to bring it up to date? This should be pretty quick assuming the server isn't watching a video or some-such. This answer suggests this is what both RDP (Microsoft) and VNC use for remote desktop viewing.
See https://stackoverflow.com/a/4098515/171703 and https://stackoverflow.com/a/1876848/171703 for some ideas on how to do this.

Related

Delivering video stream from IP cameras

I have several IP cameras. I want to get their streaming video but using an additional server to centralize the cameras. This server should get the video stream from 2-5 cameras and then, deliver it again through a different url. thereby many streaming users wouldn't overload the IP cameras which can not hold a high number of viewers.
It the first time I'm facing video streaming that's why I'm a bit lost and I don't know where should I begin from. I've any restrictions about which protocol use, rtsp, http... I'm quite free about that.
I've found this project which looks like pretty similiar to my problem. Anyway, before going deeper in it, I would like to have the opinion of someone who has develop anything similar before. Any tip would be apreciated.

How to create a virtual display?

The question is simple, but I guess the answer might not be.
I want to create a display device, on which the GPU would render a desktop or a video game. However, this device would not be connected to any physical screen on the video card port. The data rendered would be retrieved and streamed somewhere else over network.
A bit similar to what OnLive did, but I would like to stream that video output over LAN. Obviously it must be a full and real display so that existing applications or video games could work properly on it.
Is it even possible in C#?
surely you could link it up as an output stream with your processed frames, piped to a network socket or such?

Record video from camcorder in C#

I need to be able to record video from an external camera in a C# application.
Unfortunately a webcam is pretty much out of the question as the application will record outside and during the evening/night. That is why I was thinking of a camcorder since it also has manual control over exposure and focus, lower noise and better sensor.
So far I would use the AV/S-Video output from the camcorder and send the signal to a USB capture card (the computer is a laptop so no PCI-E cards).
How would I be able to access the video stream from the C# application, now that it comes from the capture card ?
Does my proposed system seem feasible (achievable, good video quality, good fps)? Does anybody have another working solution?
Thanks
This Code Project Article could be of a good starting point.
The Author mentions :
The main goal of the application was to make it flexible and
extensible. The application itself can communicate with any video
source – it may be an IP video camera or a server, it may be a local
camera attached to USB, it may be an MMS stream from a remote server,
or it may be any other video source. And more of it, the application
can work with all these video sources simultaneously, displaying them
all on a single screen.
The solution I used in the end was Microsoft Expression Encoder.

C# - What's the best way to reduce the size of an image (for streaming over tcp)

I've written an application that streams live screen to a remote app. It grabs the screen (resizes the image to 640x480) and then compresses the image using GIF compression (using System.Drawing), saves it into a byte[] array and transfers it to the other app.
The problem is that the image I get is about 50KB which means that at 30FPS it would require 1.5MB of data transferred each second. At the moment I only get 8-10 FPS. I know it's possible to solve this somehow. Maybe using the technique that flash videos use?
Personally I'd recommend using VNCSharp - it will do most of the heavy lifting for you. Some might say that it'd be madness to code this up again.
If not then streaming images is a waste of bandwidth - you need to effectively build a video stream and transmit that.
Since you don't need animation and want to stay with loss-less compression you would get somewhat better compression with PNG instead of GIF (and PNG is patent-free). According to this the savings is between 10 to 30%.
I think use screen by screen capture isn´t a good approach to get a live screen streaming. Video formats, usually, assumes that between a lot of frames you have a small couple of areas that changes. In the other hand you´ll need to work a bit more to capture a video from the screen.
You can start from these articles:
http://betterlogic.com/roger/2010/07/list-of-available-directshow-screen-capture-filters/
http://www.codeproject.com/KB/dialog/screencap.aspx
Rather than compressing images, you'd better compress video streams. This is how video codec achieve high compression : by exploiting similarities into consecutives images in the stream.
If you compress your images one by one, you loose this performance advantage, and it makes a huge difference in bandwidth.

How can I edit individual pixels in a window?

I want to create a simple video renderer to play around, and do stuff like creating what would be a mobile OS just for fun. My father told me that in the very first computers, you would edit a specific memory address and the screen would update. I would like to simulate this inside a window in Windows. Is there any way I can do this with C#?
This used to be done because you could get direct access to the video buffer. This is typically not available with today's systems, as the video memory is managed by the video driver and OS. Further, there really isn't a 1:1 mapping of video memory buffer and what is displayed anymore. With so much memory available, it became possible to have multiple buffers and switch between them. The currently displayed buffer is called the "front buffer" and other, non-displayed buffers are called "back buffers" (for more, see https://en.wikipedia.org/wiki/Multiple_buffering). We typically write to back buffers and then have the video system update the front buffer for us. This provides smooth updates, as the video driver synchronizes the update with the scan rate of the monitor.
To write to back buffers using C#, my favorite technique is to use the WPF WritableBitmap. I've also used the System.Drawing.Bitmap to update the screen by writing pixels to it via LockBits.
It's a full featured topic that's outside the scope (it won't fit, not that i won't ramble about it for hours :-) of this answer..but this should get you started with drawing in C#
http://www.geekpedia.com/tutorial50_Drawing-with-Csharp.html
Things have come a bit from the old days of direct memory manipulation..although everything is still tied to pixels.
Edit: Oh, and if you run into flickering problems and get stuck, drop me a line and i'll send you a DoubleBuffered panel to paint with.

Categories

Resources