Do I need an AVFormatContext for decoding raw audio data?

I am streaming encoded audio data to my program, in raw byte arrays. The audio data could have any encoding but when I receive the data I will know the encoding, sample rate, etc, so I know how to interpret it. Using ffmpeg/libav libraries, I want to decode the audio chunks when I receive them and do some processing with them (e.g. resampling). My question is, since I am getting raw encoded audio data that is not wrapped in a file format, do I still need to create a AVFormatContext and use av_read_frame() to get the encoded AVPacket? Or should I just create an AVPacket using av_packet_from_data(AVPacket *pkt, uint8_t *data, int size) and manually set the properties like encoding, sample rate, etc? It is my understanding that AVFormatContext is meant for representing file formats, i.e. wrappers, so I don’t know if it would work if I use raw encoded audio data (which I would access through a custom AVIOContext). Also, since I want to support lots of different audio codecs as input, I don’t know if the different frame sizes for different codecs will make it difficult to create an AVPacket, if I have the wrong number of samples in my data array, so maybe an AVFormatContext would be better.

Which is the better approach for decoding raw encoded audio chunks – creating an AVFormatContext or AVPackets?

Leave a Comment