【问题标题】:FFmpeg - How do i get the extradata required to open the ALAC Codec?FFmpeg - 如何获取打开 ALAC 编解码器所需的额外数据?
【发布时间】:2016-02-02 02:32:54
【问题描述】:

我想知道如何使用 FFmpeg 库从 ALAC 媒体文件中获取额外数据,而无需手动解析文件?

我最初设置的是:

avformat_open_input(&formatContext, pszFileName, 0, 0);
avformat_find_stream_info(formatContext, NULL);
av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
codecContext = avcodec_alloc_context3(codec);

目前我能够检测并找到 ALAC 编解码器,但它无法打开返回 AVERROR_INVALIDDATA 的编解码器,这是由于未设置 extradataextradata_size

avcodec_open2(codecContext, codec, NULL);

FFmpeg 文档指出,某些编解码器需要将 extradataextradata_size 设置为编解码器的规范。但是这些数据不应该由 avformat_find_stream_info 设置吗?

【问题讨论】:

    标签: android c++ ffmpeg


    【解决方案1】:

    是的,extradataavformat_open_input()avformat_find_stream_info() 期间填充。但是,它会将其填充到您未使用的字段中。您需要以下代码:

    avformat_open_input(&formatContext, pszFileName, 0, 0);
    avformat_find_stream_info(formatContext, NULL);
    int audioStreamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
    codecContext = avcodec_alloc_context3(codec);
    avcodec_copy_context(codecContext, formatContext->streams[audioStreamIndex]->codec);
    avcodec_open2(codecContext, codec, NULL);
    

    相关的额外行是avcodec_copy_context(),它将数据从libavformat 解复用器(在formatContext->streams[])复制到该上下文的副本(codecContext),您将使用@ 中的解码器进行解码987654329@.

    【讨论】:

    • 谢谢,我现在可以打开编解码器,但解码后我得到: V/FFMPEG:无效零块大小为 33 4096 4065 V/FFMPEG:未知预测类型:3 V/FFMPEG:无效零块大小为 26 4096 4094 V/FFMPEG:不支持语法元素:5。可能的原因?
    • 你能在某处发布完整的代码和示例输入文件吗?
    • 设法修复它。再次是实施中的问题。在使用 avcodec_decode_audio4 解码之前,我没有调用 av_read_frame(formatContext, &packet)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2012-04-12
    • 1970-01-01
    相关资源
    最近更新 更多