I'm trying to use gzip streams in C# but it appears that the files after compression are bigger than before. It's occurs when I working with .avi and .mkv files. But if I working with .txt and .html compressed file smaller than original.
using (MemoryStream output = new MemoryStream(blockToCompress.Length))
{
using (GZipStream cs = new GZipStream(output, CompressionMode.Compress))
{
cs.Write(blockToCompress, 0, blockToCompress.Length);
}
}
I solved this problem by checking the Framework (from 3.5 to 4.0) without editing the code.
Your code is correct. Unfortunately, your expectations are not.
Most video and audio files are already heavily compressed. They won't be able to be compressed any further with lossless compression like GZip. In fact, you might slightly increase file size - every file format, GZip included, carried with it some overhead/bookkeeping.
If you truly need to reduce their size, you'll need to use a lossy compression scheme that comprehends the video format. Basically, you'll be removing data, probably reducing apparent quality, in exchange for a smaller size.
Lossless compression schemes like GZip can reduce file size by 25-50%, if the source content is uncompressed. Files with lots of repeated text (HTML) or English text (general text files) usually compress much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With