I need to write C++ function to transcode any mp3 file to G.711 encoded wav file using LibAV API. Since we run on custom ARM board, I can use only specific available cross compiled version of LibAV library (pretty old, not the latest one).
Here is my plan how to implement such function. Please advise if it make sense or I misunderstand the transcoding flow.
1. Decode mp3 file
2. Encode uncompressed data with audio codec CODEC_ID_PCM_MULAW
3. Mux encoded data to wav container
The very simplified flow (without error checking and initialization details) is as follows:
avformat_open_input(&format, sMp3FileName, NULL, NULL);
avformat_write_header(oc, NULL);
while (av_read_frame(format, &packet) >= 0)
{
// Decode one frame
avcodec_decode_audio4(codec, frame, &gotFrame, &packet);
// Encode one frame
avcodec_encode_audio2(pCodecCtx, &packet_out, frame, &gotFrame);
// Dump packet to wav file
av_interleaved_write_frame(oc, &packet_out);
}
av_write_trailer(oc);
Please review and advise. Thanks in advance.