Reduce WAV file size using cscore library - cscore

I want to reduce WAV file using cscore libary without loosing audio, something like NAudio
var pcmStream = WaveFormatConversionStream.CreatePcmStream(inputSteam);
var wavCompressedStream = new WaveFormatConversionStream(target, pcmStream);

You can change the format of a wave file with by opening the existing audio data as IWaveSource, changing its format and writing it back to any stream or file.
For example:
IWaveSource waveSource = ...
waveSource
.ToMono() //for example, convert to mono
.ChangeSampleRate(44100) // specify samplerate
.ToSampleSource()
.ToWaveSource(16) //specify bits per sample
.WriteToWavStream(stream);
But keep in mind that you probably will loose audio quality by downsampling, changing bits per sample, ...

Related

Rascal MPL get line count of file without loading its contents

Is there a more efficient way than
int fileSize = size(readFileLines(fileLoc));
to get the total number of lines in a file? I presume this code has to read the entire file first, which could become costly for huge files.
I have looked into IO and Loc whether some of this info might be saved in conjunction with the file.
This is the way, unless you'd like to call wc -l via util::ShellExec 😁
Apart from streaming the file and saving some memory counting lines is always linear in the size of the file so you won't win much time.

Can i remap and compress a NETCDF at the same time?

I got a huge set of data and i need to remap it to a new size of pixel. But this operation generate a big file that fills my hard drive...
i'm using that:
cdo remapnn,r7432x13317 petcomp.nc FINAL.nc
So, can i compress and make this operation at the same time?
The following modification to your code should work:
cdo -z zip -remapnn,r7432x13317 petcomp.nc FINAL.nc
Read the CDO user guide to see other compression options if you need to get as small as possible.

Read a locally stored image as the background image for subtraction

I'm using Emgu.CV and planning to use background subtraction. I want to do something fairly simple and read two background images from my local disk, and use one of them as the background image and the other one as the overlay to compare with / the mask.
I haven't got far though, because the signature of the method is very different than just accepting a file. I'm guessing I'm missing some conversion from a File.Read to IInputArray
IBackgroundSubtractor backgroundSubtractor = new BackgroundSubtractorMOG2();
IInputArray inputImage; // how do I create an instance of an InputArray from a local file?
IOutputArray mask;
backgroundSubtractor.Apply(imputImage, mask);
How do I go from a file in C:\<somepath>\someimage1.png to formats IInputArray, IOutputArray below?
EmguCv offers different methods to load images from file (see V1 and V2 below). For the mask you just need to define a new Mat object and it will be allocated and filled automatically when you call backgroundSubtractor.Apply(input1, mask);
//V1 load image
var input1 = new Mat(#"C:\<somepath>\someimage1.png");
//V2 load image
Mat input2 = CvInvoke.Imread(#"C:\<somepath>\someimage1.png", ImreadModes.AnyColor);
var mask = new Mat();
IBackgroundSubtractor backgroundSubtractor = new BackgroundSubtractorMOG2();
backgroundSubtractor.Apply(input1, mask);
The Mat class implements IInputtArray as well as IOutputArray.

Get the real extension of a file vb.net

I would like to determine real file extension.
example :
file = "test.fakeExt"
// but the real extention is .exe // for security reason I wish to avoid using it!
How can I do that?
If you want to determine the extension you could use findmimefromdata.
It looks at the first part of the file to determine what type of file it is.
FindMimeFromData function
Sample code
The first two bytes of an .exe file are allways 'MZ'.
So you could read the binary file, and see if the first two bytes are MZ, then you know it's an .exe file...

Load raw memory blob in DPX format with Graphicsmagick

I have a library that generates a Big Endian 10-bit DPX image in a memory buffer. It's just the raw 10-bit RGB data, though, with no headers. I'm trying to load this data into an instance of Magick::Image like this:
Magick::Blob blob(dataBuffer, dataBufferSize;
image.read(blob, Magick::Geometry(width, height), 10 /*bits*/, "DPX");
This throws the following exception, though: Magick: Improper image header ()
Is it possible to load a raw DPX into a Magick::Image?
I don't think that your answer is a good one. It it is working by accident. Your blob data is likely to be in some other format than DPX. Specifying 'SDPX' (an unsupported format specification) allowed the file format detection to automatically work and select the correct format.
Using
enter code herMagick::Blob blob(dataBuffer, dataBufferSize);
image.read(blob);
should then be sufficient. Most image file formats do not require specifying the format or the depth.
Figured out my own answer here. I took a look at the DPX loading source and found out for this case this line:
image.read(blob, Magick::Geometry(width, height), 10 /*bits*/, "DPX");
should be:
image.read(blob, Magick::Geometry(width, height), 10 /*bits*/, "SDPX");

Resources