Search code examples
c++audioffmpeglibavformat

Open raw audio with avformat_open_input


I want to fill ffmpeg.formatCtx for raw(LINEAR16,48000khz) audio file using avformat_open_input().

I've tried to pass own AVInputFormat, but not suceeded in it.

This is how i used to open file.

std::string fn = "file:" + this->file.path;
int r = avformat_open_input(&ffmpeg.formatCtx, fn.c_str(), nullptr, nullptr);

Tried to find needed format with av_find_input_format(), but not succeeded to0.

Without input format ffmpeg determines file as mp3.

Is there convenient way to do such case?


Solution

  • The main things that gets done in avformat_open_input are:

    • Allocate memory for AVFormatContext and fill AVFormatContext.
    • Tries to guess the input file format, codec parameter for the input file.

    Because you only have raw audio data, you need to allocate memory for AVFormatContext and fill AVFormatContext by yourself.

    Otherwise, the raw audio data don't need to demux and decode, I think you should not use avformat_open_input.