【问题标题】:Open raw audio with avformat_open_input使用 avformat_open_input 打开原始音频
【发布时间】:2019-11-05 10:28:35
【问题描述】:

我想使用avformat_open_input()raw(LINEAR16,48000khz) 音频文件填充ffmpeg.formatCtx。

我尝试传递自己的AVInputFormat,但没有成功。

这是我以前打开文件的方式。

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

尝试使用av_find_input_format() 找到所需的格式,但没有成功到0。

没有输入格式的ffmpeg判断文件为mp3

有没有方便的方法来处理这种情况?

【问题讨论】:

  • 样本大小、类型、字节顺序、频率等的值不存储在原始音频流中,因此 ffmpeg 无法读取它们。您必须在编解码器上下文中手动设置它们。

标签: c++ audio ffmpeg libavformat


【解决方案1】:

avformat_open_input 中主要完成的事情有:

  • 为 AVFormatContext 分配内存并填充 AVFormatContext。
  • 尝试猜测输入文件格式,输入文件的编解码器参数。

因为你只有原始音频数据,所以需要为 AVFormatContext 分配内存,自己填充 AVFormatContext。

否则,原始音频数据不需要解复用和解码,我认为你不应该使用avformat_open_input。

【讨论】:

    猜你喜欢
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多