Header missing error while decoding .mp3 file using FFMPEG - audio

[mp2 # 0x555556aea340] Header missing
Error submitting the packet to the decoder
This above error is getting and i am unable to find out the reason.
I am decoding mp3 audio file using FFMPEG decode_audio.cpp pgm for which link is:
https://www.ffmpeg.org/doxygen/4.1/decode_audio_8c-example.html
I want to decode file into .wav file.
if anyone can answer this it would be helpful for everyone whoever in future doing audio decoding part.

codec = avcodec_find_decoder(AV_CODEC_ID_MP2);
if (!codec) {
fprintf(stderr, "Codec not found\n");
exit(1);
}
This is for the MP2 audio codec to decode the audio. You need to customize the code for mp3.

Related

FFMPEG - How to add a default codec for wav using -filter_complex

Is it possible to set the audio codec via -filter_complex in FFMPEG?
My Google-fu is weak and I haven't had good hits so far.
I'm working on a fork of a (possibly abandoned) project, and this is currently the -filter_complex argument:
[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.0[audout0]
How do I set the audio codec here?
I've tried:
[0:a]aformat=sample_fmts=fltp:sample_rates=44100:acodec=pcm_s16le:channel_layouts=stereo,volume=1.0[audout0]
by adding: acodec=pcm_s16le
But this results in: Option 'acodec' not found
I'm trying to accomplish is adding a default audio codec for a .wav output, because the system complains that there's no default audio codec chosen for a wav output, because I get this error message with my project when I try to output to .wav:
Automatic encoder selection failed for output stream #0:0. Default encoder for format wav (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:0
Thanks!

fluent-ffmpeg: Convert wav to alac .m4a with streams

On my node.js server I want to convert a wav file to apple lossless .m4a
Using fluent-ffmpeg, I got this so far:
const transcoder = ffmpeg(fs.createReadStream(`${__dirname}/convertTest.wav`));
transcoder
.withAudioCodec('alac')
.addOutput(fs.createWriteStream(`${__dirname}/test2.m4a`))
.run()
;
But it throws me the following error:
Error: ffmpeg exited with code 1: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Conversion failed!
I read that mp4 container needs a seekable file an therefore doesn't work with streams. So this actually works:
const transcoder = ffmpeg(`${__dirname}/convertTest.wav`);
transcoder
.withAudioCodec('alac')
.save(`${__dirname}/test2.m4a`)
.run()
;
Since I have all files as streams and not physical files, I am looking for way to somehow abstract this away to make it work with streams. Is this possible with fluent-ffmpeg?
The alac codec and .m4a format is non optional, so I need it to work with those formats.
Turns out that the ALAC codec does not support streams because the file head has to be read at different times. So I had to use it without streams.

SIM800C : Uploaded audio AMR file has noise when played during call

I am able to upload the AMR file to SIM800C successfully.
When I play the uploaded audio file during the call using the below command :
#if CALL_RECORDED_AUDIO
Serial1.print("AT+CMEDPLAY=1,C:\\REC\\");
// "Command Media PLAY" -> to play an audio if it is a recorded audio
#else
Serial1.print("AT+CMEDPLAY=1,C:\\User\\");
// "Command Media PLAY" -> to play an audio if it is a uploaded audio
#endif
Played audio always has noise, from C:\User\.
However if I record the audio during call and save it. Play the recorded audio during next call then there is no noise. ( By defining CALL_RECORDED_AUDIO in above code snippet)
according to the documentation of the sim800 it is necessary to play a sound wav during the call
Note
. mode 2 and 3 are not supported when playing audio file during call.
. The audio file can not be played duirng incoming call or outgoing call.
. Only support WAV, PCM, AMR and MP3 format.
. Only support WAV format with 8K 16bit during call.
page 201/202 of the sim800 guide
personally i did not suck having no sim800
I think the recording of a call must be in .WAV format
let me know if it works

Convert from PCM to WAV. Is it Possible?

I have an application for iPAD.
This application records the voice of the microphone.
The audio formats of the item must be PCM, MP3 and WAV files. The MP3 file I get it starting from the original raw file and then convert using LAME.
Unfortunately I have not found any example that allows me to convert a PCM file to a WAV file.
I just noticed that if I put the file extension to WAV format, starting from the raw application saves without problems, so I think that there is no type conversion from PCM WAV files.
Correct?
PS: Sorry for my english ... I use Google Translate
WAV is some kind of a box. PCM is in the box. There are many container formats like MP4. MP4 can contain audio, video or both. It can also contain multiple video or audio streams. Or zip files. Zip files can contain text files. But zip files can also contain images, pdfs,... But you can't say "how can I convert a zip file to the text file inside the zip".
If you want to convert PCM data to a WAVE file you should not many problems because WAV files are quite simple files. Take a look at this:
(See also WAVE PCM soundfile format.)
You first need that header and after you can just append all your pcm data (see the data field).
Converting PCM to WAV isn't too hard. PCM and WAV both format contains raw PCM data, the only difference is their header(wav contains a header where pcm doesn't). So if you just add wav header then it will do the tricks. Just get the PCM data and add the wav header on top of the PCM data. To add wav header with PCM data, check this link.
I was working on a system where it accepts only wav files, but the one I was receiving from amazon Polly was pcm, so finally did this and got my issue resolved. Hope it helps someone. This is an example of nodejs.
// https://github.com/TooTallNate/node-wav
const FileWriter = require('wav').FileWriter
let audioStream = bufferToStream(res.AudioStream);
var outputFileStream = new FileWriter(`${outputFileFolder}/wav/${outputFileName}.wav`, {
sampleRate: 8000,
channels: 1
});
audioStream.pipe(outputFileStream);
function bufferToStream(binary) {
const readableInstanceStream = new Stream.Readable({
read() {
this.push(binary);
this.push(null);
}
});
return readableInstanceStream;
}

NAudio - 1.7 - Converting WAV to MP4

I am trying to convert a PCM Wav file recorded with the WasapiLoopbackCapture class to an AAC file. The Wav file is 44100, 32bit, 4 channels.
using (var reader = new MediaFoundationReader("recordedfile.wav"))
{
MediaFoundationEncoder.EncodeToAac(reader, "encodedfile.mp4");
}
However, i get a COMException from the MediaFoundationReader:
Exception from HRESULT: 0xC00D5212
What am i doing wrong here and what would be the proper way to convert from PCM WAV to AAC?
Thanks
This probably means you haven't got an AAC encoder (or something is up with the WaveFormat of your recorded WAV file). What version of Windows are you using?
I battled this problem for a few days before ultimately discovering that you need to install The Microsoft Media Foundation AAC Decoder.
https://superuser.com/questions/819227/how-to-fix-missing-media-foundation-microsoft-aac-audio-decoder-transform-mft-wi
https://www.microsoft.com/en-us/download/confirmation.aspx?id=13283

Resources