Converting Wav in MP3 - c++

How can I convert WAV in MP3 using QtMultimedia?
There is some specific class for reading WAV and writing MP3 files?

As far as I know there is no MP3 encoder packaged with Qt. You'll have to use an external library.
Edit: this is confirmed by this thread at least as far as Qt4 is concerned (no idea about Qt5 though but I suspect it's the same).

Related

Problem Converting WAV file with more than 2 channels to MP3

I am developing a C# application that records streaming audio to MP3.
I’m new to this but from what I’ve seen so far, the easiest way to do this is record to WAV using NAudio and then create an MP3 version using either LameMP3FileWriter or MediaFoundationEncoder.
I’m running into problems with the conversion, however, as my PC sound system is 5.1 and the MP3 conversion crashes due to the number of channels in the recorded WAV file. It works fine when I reconfigure my sound system to stereo but this is a bit of a pain; firstly, it means I cannot use my 5.1 system when recording the music but more of an issue, for some reason that I cannot figure out, if I set my speakers to stereo, they revert to quadraphonic when the PC (Windows 10) is rebooted!
Can anyone suggest how I can do this conversion without the need to configure my 5.1 sound?
One obvious solution to do something like resampling the WAV file to 2 channels before the conversion to MP3 but that seems something of a ‘long shortcut’. I’m also unclear as to the advantage of recording to WAV in the first place – audio streams are compressed and unlikely to have more than 2 channels to start with so playing it over 5.1, no matter how good it sounds, is really a bit illusory.
It would seem more sensible to just record the stream direct to MP3 but I cannot find any straightforward way of doing that.
Mp3 specification does not handle 5.1. So it seems your mp3 encoders fail with 5.1.
Perhaps you can try an encoder that support MP3 Surround, an mp3 extension for 5.1.
Also, Perhaps you should consider using AAC encondig, a more friendly codec for 5.1.

How can I stream sound from the microphone in mp3 format?

I need a software that can stream audio with mp3 format.The audio will come from the microphone at the same time.
I have a software that can stream sound with alaw and ulaw codecs.
And I have an another program that can stream recorded mp3 file. Not capture from the microphone.
I can make stream with VLC.Dotnet wrapper but I didn't succeed with directshow.(namely microphone)
Here my Vlc.Dotnet code;
myVlcControl.Play("dshow://");
myVlcControl.Play(new Uri("dshow://"));
It did not work with this codes. I don't know what causes the problem.
My second software can stream sound that captures form microphone in real time. But its codec format is alaw not mp3. I did not find any converter that convert linear to mp3 file. I find a converter that convert linear to alaw. this is the link Linear to Alaw Codec
I know the LAME and NAudio but it converts wav file to mp3. I need linear to mp3(like in the link)
I am very confused. I really do not know which way to go.
1. Find a codec linear to mp3 (It's very complicated) ?
2. Learn VLC direct Show usage on .NET ?
Thank you so much in advance.
*VLC.DotNet, axVLCPlugin21, LAME, ffmpeg....
As soon as I've successfully solved this problem with VLC.Dotnet wrapper. The problem is compiling with x64 architectural. When I was compiled with x86 architectural, The problem solved.

How do I play .wav files in C++ on Linux?

I have a question about playing .wav files in C++. I search for a method to play it on Linux and Windows and I want to break up it while a function has been ended, did you know a sample for this?
Thanks for any Answer :)!
I am from Germany, please don't be angry about my grammar or spelling :D.
There are several ways to do this.
The simplest, ugliest and most hackish way to do this is to write directly to your sound device located in /dev/snd/. However this really depends on your linux distribution and some modern ones no longer allows you to do this. In general, direct read / write to /dev/ devices is fading away. Here is a question answering this.
For a very long time, the "official" way was to use alsa library which uses a C style interface. It is usually pretty tricky, full of pitfalls and "workarounds" that depends on your exact audio hardware.
I think that alsa is getting gradually replaced by jack, which I hope is easier to use. I don't have any experience with this one.
The last method I know is with portaudio, which as the name implies, is somewhat portable between at least windows, linux and osx.
All of these library will allow you to control your audio hardware, init / setup / play. What is simple about wav files is that the content is raw pcm, which is usually the format used by those libraries. The wav format is usually like this :
[wav header] [audio data until the end of the file]
If you can manage a few milliseconds of garbage when you start playing, you can "safely" send the header for playback as well and avoid parsing it. You will have to understand PCM formats however and should bring some additional readings.
As an added "trick" which doesn't directly concern C++, I strongly suggest using Audacity. It is a small program which I see like the notepad / vim of audio files. It is small, it loads fast, allows you to copy / paste segments of audio and detect pcm formats. (Actually, you just change pcm settings until the audio "sounds" right, but still useful)
The title mentioned Linux, but then you mentioned Windows and Linux in the post.
For Linux, best is to use gstreamer if you insist on C++. Look through the gstreamer code for gst-launch. It is run as below in a Linux machine.
$ gst-launch filesrc location="location of file" ! wavparse ! alsasink
From, http://sanchayanmaity.github.io/beagleboard-xm/linux/programming/software/2014/08/07/playing-wavmp3-file-using-gstreamer-in-code.html
For windows, or if you want to use OS agnostic code on both Windows and Linux, you can use SDL,
http://lazyfoo.net/SDL_tutorials/lesson11/
Another alternative (cross-platform, Object oriented), is SFML. Check the audio wav file playback example at,
http://www.sfml-dev.org/tutorials/2.0/audio-sounds.php

How to decode mp3 into wav using lame in C/C++?

I learned how to encode wav into an mp3 using lame_encode_buffer_interleaved from this question: Is there any LAME c++ wraper\simplifier (working on Linux Mac and Win from pure code)?
Now I want to decode the mp3 back into wav. I know there's lame_decode but I don't know how to use it since it requires two pcm buffers (pcm_l and pcm_r). I don't understand how to put them together into a well-formed wav file, because I don't really know how they works.
Now can someone provide a simple working example on decoding an mp3 into a wav using lame in C/C++?
Thanks.
Take a look into the lame frontend source code. Start at the lame_decoder() function in the .../frontend/lame_main.c file, it decodes an MP3 file and writes the wave header.

Audio track in video file - C++

My application is transforming an AVI video file into another AVI file. I use
the OpenCV library. Unfortunately videos created with OpenCV have no sound as the library does not support audio.
Is there any easy way to copy the audio track from one video file to another? Maybe FFmpeg?
My application is written in Visual C++.
You can use FFmpeg. The easiest way would be to just use the command line tool to extract/reassemble. If you need your application to do it itself, looking into the sources for how they do it should help.
Alternatively, as you mention VC++, why not use DirectShow? It should not be too difficult to sink the audio into a file for extraction and later sink the video/audio mix into a file for composition.