Direct Show Decrease Video File Size - c#

I am using direct show to capture video and save it to file. I have tried in vain to find ways to decrease the resultant video size but cannot manage. I would like to know if anyone can tell me how I can:
Decrease the frame rate of the video
Decrease the quality of the video (even down to 320 x 240)
Apply a compression on the video (mpeg? etc).

Raw video is huge in size, and to size-efficient storage assumes you compress the video. You are to use one of the video encoders, such as MPEG-4 AVC (H.264) or Windows Media. You typically insert an additional filter into your pipeline between capture filter and multiplexer/file writer. Read up on this in multiple past topics:
Using video codecs like XVid in c#
Real-time video encoding in DirectShow
How to properly build a directshow graph to compress video...

Related

Show webcam stream with delay

I've been trying to find a way to show the stream of my webcam with a 30 second delay.
I found out that VLC is able to do this, but the problem is that the framerate is much too low and it's not smooth or viewable at all. I have to run this on a fairly old laptop with a better webcam that I own now, so I guess it's not an option.
I am able somewhat familiar with c#/c++ and python so I thought that I might make a solution of my own as the task seems fairly easy. Though, the problem is, I don't know where to start and any nudges in the right direction would be much appreciated.
My initial idea was to record first 30 seconds of the stream to the disk, then use VLC to view partial file (AFAIK it's able to do that). Is it an idea worth working on or should I scratch it and use some sort of a buffer for the video frames in the last 30 seconds?
Again, any nudges in the right direction will be much appreciated, thanks!
Take a look at OpenCV.
It can retrieve and show images from a webcam.
A lot a of tutorials are also available; e.g. http://opencv.willowgarage.com/wiki/CameraCapture
So simply create an array (or whatever) to hold the amount of pictures to be expected in 30 sec (FPS*30).
Start to retrieve images and as soon as the array is filled start to play from position 0.
Newly retrieved images can than be stored at the position from the "just" shown image.
Miguel Grinberg has written an excellent video streaming tutorial in Python which sends JPEG frames successively. Check his blog post here:
http://blog.miguelgrinberg.com/post/video-streaming-with-flask1
Each of these JPEG can be quickly reviewed and then broadcasted. [To take the required Delay in consideration]
As far as getting the input video feed is concerned, you can interface a webcam using OPENCV. OpenCV uses VideoCapture which returns raw images as bytes. These bytes needs to be encoded to JPEG and interfaced with Miguel's code.
import cv2
class VideoCamera(object):
def __init__(self):
# Using OpenCV to capture from device
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# so we must encode it into JPEG in order to correctly display the
# video stream.
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
This approach will help you cater all the required features:
No internet required
Adjustable delay - Easily control the delay and the processing you want to perform on each frame
Good Quality
Record on Demand - Store the captured frames as per need
Have a record back feature, by just saving the previous 24*x frames (24fps stream)

Using video codecs like XVid in c#

I'm trying to develop an application which captures a series of images from web cam using DirectShow.Net and then sends it over network to other clients.
Everything is working fine, except the images are too big and compression methods like using GZipStream, JPEG Compression and etc does not help more about reducing the size.
Now, I want to know how to using codecs like XVid or any other codec, to reduce the size.
Playing around the demos of VisioForge, it approves that XVid files are too smaller than regular AVI files.
Thanks for any help
There are specific video compression algorithms, which effectively compress video, some of the most popular are: M-JPEG, MPEG-4, H.261, H.263, H.264, VP8, Theora. In DirectShow the video compression items have form-factor of video compression filters (or codecs). Standard Windows does not normally include much for this task (for various reasons, patents to specifically mention), so you need to use a third party or otherwise installable codec. Luckily, the codecs have more or less uniform interface and you use them similarly from C#.
See related questions with helpful information:
Real-time video encoding in DirectShow
Capturing webcam using DirectShow.NET library
Be sure to check DirectShow.NET samples out:
\Samples\Misc\DxWebCam
A poor man's web cam program. This application runs as a Win32
Service. It takes the output of a capture graph, turns it into a
stream of JPEG files, and sends it thru TCP/IP to a client
application.
\Samples\Capture\CapWMV
A .NET sample application using the WM ASF Writer filter to create an
wmv file

Grab frame from .mov file using DirectShow.net

How to grab frame from .mov file in c#.net by using DirectShow.net
DirectShow and DirectShow.NET don't make it any special with .MOV files. You typically create a filter graph with a Sample Grabber filter that you manage, and its callback gives you frames of video stream that passes through.
You might want to look at DxScan sample in DirectShow.NET, \Samples\Editing\DxScan. It grabs frames from a given movie file.
A sample application scanning a media file looking for black frames
Most of the work is done in ISampleGrabberCB.BufferCB. See the comments
there. Also, the algorithm used to scan for black frames isn't as efficient
as it could be. However, the samples gives you an idea of how this could be
done.

Record video from opengl

I am using Tao framework and I have a simple opengl control.
How can I record a video from this control and save it to a file?
See here for a link that mentions both Bitmap screen capture in C# and starts to describe the AVI conversion.
For further information about the library used to in the first link to make an avi file from a collection of bitmap images see here.
See here for an example that uses the Media Player Encoder in order record the screen.
The more complicated and direct way would be to either use a video capture card or write a software device that emulates one and feed that source to DirectShow filter using DirectShow.Net or Pinvoking other DirectShow libaries directly.
How can I record a video from this control and save it to a file?
Use glReadPixels to get the pixel data. Feed the pixel data into a video encoder (e.g. a DirectShow filter graph, or through ffmpeg/libavcodec or sump the images into files and encode them to video later).

AVI Compression - CBR not configurable

I wrote a C# code that captures video from a video capture card, and writes it in a AVI file. I'm using the XviD encoder (DirectShow).
I'm using the IAMVfwCompressDialogs interface to get the configuration form open, and I am also trying to configure it going to the same form in the start menu.
I need to record 30 minutes of video, without audio, and I need this file to be 2Mb big.
I set the Target bitrate property of the Video Encoder of the Xvid to 10 (kbps), and the Target Quantizer property to 16.
The file size did not changed.
Then I tryed to modify those two property to many different combinations, but I get no change.
My problem is: I changing the XviD configurations to change the file size, modifing the bitrate and the quality properties, but the result is aways the same.
Is there any way I can set 30 minutes video file size to be around 2Mb big, even by modifing the bitrate or quality, with 1 fps, 240x192 framesize, very low video quality? Is there any problems with XviD filter when using it on a C# service? Is there any other good filter to use with DirectShow on c# applications?
Thanks in advance.
I found out how... It may sound weird, but when I set the windows service to inicialize with the same user that installed the Xvid codecs, it works fine.

Categories

Resources