I have a problem when trying to open a binary file containing raw audio data in opus
format. When I try to open this file, the library returns an error: Unknown input format: opus
.
How can I open this file ?
I need to open it and write all the raw audio data to an audio container. I understand that the opus
format is intended only for encoding
. I realized this using command:
$ ffmpeg -formats | grep Opus
ffmpeg version 3.4.4 Copyright (c) 2000-2018 the FFmpeg developers
E opus Ogg Opus # For only encoding
Then what format should I use to open this file ? With ogg
? I tried, but there are also problems with opening the outgoing file. I provide the code that shows only the necessary part to open the file:
int main(int argc, char *argv[])
{
// ...
av_register_all();
AVFormatContext *iFrmCtx = nullptr;
AVFormatContext *oFrmCtx = nullptr;
AVPacket packet;
const char *iFilename = "opus.bin"; // Raw audio data with `opus` format
const char *oFilename = "opus.mka"; // Audio file with `opus` audio format
AVDictionary* frmOpts = nullptr;
const qint32 smpRateErrorCode = av_dict_set_int(&frmOpts, "sample_rate", 8000, 0);
const qint32 bitRateErrorCode = av_dict_set_int(&frmOpts, "bit_rate", 64000, 0);
const qint32 channelErrorCode = av_dict_set_int(&frmOpts, "channels", 2, 0);
if (smpRateErrorCode < 0 ||
bitRateErrorCode < 0 ||
channelErrorCode < 0) {
return EXIT_FAILURE;
}
AVInputFormat *iFrm = av_find_input_format("opus"); // Error: Unknown input format
if (iFrm == nullptr) {
av_dict_free(&frmOpts);
return EXIT_FAILURE;
}
qint32 ret = 0;
if ((ret = avformat_open_input(&iFrmCtx, iFilename, iFrm, &frmOpts)) < 0) {
av_dict_free(&frmOpts);
return EXIT_FAILURE;
}
// We're doing something...
}