I am currently working on a tool to convert game media assets of multiple proprietary formats and converting them to more open formats. I am attempting to use the libav library http://libav.org/ to decode from WAV,mp3,ect format to a raw pcm std::vector<char>
(got that done successfully) and then encode that into ogg vorbis. I am attempting to use the api-example.c
in the documentation. https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decoding_encoding.c but have had little progress as I am getting stuck at where the tone generation ends and AVPacket encoding begins.
Could someone point me to a working example of audio encoding from raw pcm file (or std::vector
) that writes out to a file (preferably ogg vorbis)?
Few things which you need to keep in mind while encoding audio using libav:
What is the pcm sample format of the decoded frame(e.g. AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP etc.)
How many samples per channel are there in the decoded frame.
Each audio encoder takes only a specific type of sample format so if the pcm sample format is not same as the sample format of encoder than you have to do sample format conversion.
Each audio encoder takes a particular no. of samples per channel in a frame.
e.g. MP3 takes 1152 samples per channel, aac-main/lc takes 1024 samples per channel aac-he takes 2048 samples per channel. so you have to do some buffering in order to provide the expected no. of samples to the encoder.
In order to do sample format conversion I would suggest you use swr_convert api which is inside libswresample.