C#/Android Compatible Compression Algorithm - c#

I have a lot of plain-text content (English). I have a C# tool for creating the content, and it will be consumed in an Android app.
I need, therefore, to know my options for compression algorithms. What library can I use to compress/decompress, where I can compress in C# and decompress in Java?
I'm looking at probably 1-2MB of uncompressed text (at least), so it's definitely worth it to compress it.

You should be able to zip in C# using something like this and unzip with this. GZIP format should do the trick.

Related

Compress multiple jpeg files together in C#

I was trying compress jpeg files (say 16 files) together using C#. I did successfully created a tar file and finally a tar.gz (using C# GZipStream class). But the problem with my solution is that the gzip pass increased for 37% the size of the tar file (so a compression ratio of 137%). I tried to manually compress the files together using winrar and it gave me a reduction of 10% in the size (compress ratio of 90%).
I believe that my problem is with GZipStream. I think I should go for another kind of compression (or compressor?!), do you have any idea/suggestion of compression to use.
The framework's compression routines don't always go a great job.
I would recommend trying DotNetZip to compress this. My experience is that the compression (even Gzip) there is much closer to other software, and far smaller than the framework classes. This is also nice in that it requires nearly no code changes from the framework's GzipStream class if you want to use their GzipStream implementation.

Compressing XML File

All,
I have a requirement to Compress an XML file. At the moment I am using C# and the gzip algorithm in the .NET Classes. I does compress it but not at the rate I would like to.
For example a 12MB file was compressed to a little less than 4MB.
Is there any other way to compress it more than that? Speed of compression / decompression is not very important.
Thanks,
M
ZIP compression is well suited for compressing XML data. In .NET you best rely on third party libraries:
DotNetZip
SharpZipLib
You may try 7zip.
7-zip has an SDK.
Use the client version of 7-zip to try different compression settings to find the one with best compression for your particular data set.
This website compared different compression libraries against large amount of text data. 7-zip is also included. I hope that this helps you to choose correct library that matches your requirements.
Take a look at System.IO.Packaging.ZipPackage in WindowsBase. It's the .NET framework code behind the DOCX & XLSX file formats and these are more or less zipped XML files. You can zip multiple files of any format together, not just XML.

C# Primer or example on working with files on a granular level

Can someone provide an example or primer on working with files on a granular level with C#. Let's assume that I want to build a new program to compress and zip files. Can I write a program like this, with C#, that gets down to the bits & bytes level?
You can surely read files byte by byte by using FileStream-class and the StreamReader-class. BinaryReader is even more granular. Having the bytes you will have the possibilty to work on bit-base with the bit-operators (|, &, <<, >>).
Examples can be found at the posted links.
P.S: You could use SharpZipLib or the Compression classes of .Net to compress files.
I do not know of a good tutorial but BinaryReader is a good place to start for reading on the "bits & bytes" level
You can download the free #ziplib library including C# source code here:
http://www.icsharpcode.net/opensource/sharpziplib/
That should show you how to zip files at least.

How to split AVI files

I am trying to split a large AVI 2.0 (OpenDML format) file in smaller parts (under 1GB in my case) in order to be able to open the parts with VFW (avifil32.dll).
What is the best way to achieve this splitting (preferably in C#)?
One of the options is to copy it frame by frame. I found some examples on the net, which do the same. But most of these use VFW which can't read files above 2GB in general and AVI 2.0 files above 1GB because of the max RIFF part size of 1GB.
I would need DirectShow instead of VFW. I am pretty sure that I would also mess up the audio sync if I try to manually copy frames.
I am looking for something similar to what VirtualDub does with "direct stream copy" that doesn't affect the current compression, just splits the file and creates proper AVI indexes.
Avi files can be encoded in many different ways, depending on the codec used. Avi is a wrapper file, not an encoding method. This means there isn't really an easy generic way to split avi files using C#.
To do it in code from scratch would be a major undertaking. That said, you can cheat by using mencoder and calling it from c# - not ideal, but far easier and more reliable than trying to re-invent the wheel. Alternatively, there are a number of ffmpeg c# wrappers that will give you access the ffmpeg tools (but I haven't found one that isn't buggy as hell)
What are you trying to do, exactly? Why do you need avifil32.dll and how are you using it? If you are just trying to play a very large avi file, there are alternatives. Try aforge.net, for example.
mencoder can split files for you. Another option is ffmpeg

What is the easiest way to convert a compressed wav file to an uncompressed wav file in C# or C++?

What is the easiest way to programatically convert a compressed wav file (MPEG codec for example, but could be any installed codec) to an uncompressed wav file (16 bit PCM)?
I've heard that using direct show and writing the code in native C++ would do it, but I've not had much experience with direct show.
Is there an easier way to do this? C# that would be ideal, but C++ would also be fine too.
DirectShow is probably the best way to do the decoding, assuming we're talking about Windows. DirectShow is a COM API, so you could write native C++ COM code, you could use one of the available DirectShow .Net wrappers or you could use C++/CLI. Which one you choose depends on the rest of your application architecture - if you need to use .Net then C++/CLI is definitely the easiest route. You really need to be a bit more specific about what you're trying to achieve - for example, MPEG itself is not a codec - they just define standards.
You can decompress WAV files in C# using any ACM codec installed on your PC using NAudio. Here's some sample code:
using (WaveFileReader reader = new WaveFileReader(inputFileName))
{
using (WaveStream convertedStream =
WaveFormatConversionStream.CreatePcmStream(reader))
{
WaveFileWriter.CreateWaveFile(outputFileName, convertedStream);
}
}

Categories