Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: video compression using aforge.net

My application receives a sequence of images (BitmapImage) from external device with rate 30 fps. I'm using Aforge.net library for save the received stream in .avi file. I used the following code for inizializing the AVIWriter:

AVIWriter writer;
writer = new AVIWriter("wmv3");
writer.FrameRate = 30;
writer.Open("test.avi", 320, 240);

And for each frame received I add it in the video stream, with the following code line:

writer.AddFrame(ResizeBitmap(BitmapImage2Bitmap(e.ColorFrame.BitmapImage),320,240));

But the generated file is too heavy. (10 secondos corresponds to about 3Mb).

I tryied also setting a low level of writer.Quality , but the result seems the same (just 5-7% less).

So, I need a more efficient compression.

What are the compressions supported in Aforge.net ? What compression should I use in order to reducing the weight of saved file?

like image 630
pask23 Avatar asked Mar 24 '23 21:03

pask23


1 Answers

I suspect that interframe compression is not used in AVIWriter (but I may be wrong). You may try to use VideoFileWriter from Aforge.Video.FFMPEG instead:

var writer = new VideoFileWriter();
writer.Open("test.mpg", 320, 240, 30, VideoCodec.Default, 1000);
// add your frame
writer.WriteVideoFrame(frame);

Remember to put dlls from Externals/ffmpeg/bin from AForge zip into your output directory.

like image 195
Matis Avatar answered Apr 05 '23 07:04

Matis