【问题标题】:Handling ffmpeg library interface change when upgrading ffmpeg升级 ffmpeg 时处理 ffmpeg 库接口更改
【发布时间】:2020-07-09 02:46:17
【问题描述】:

我们目前正在尝试升级我们程序使用的 ffmpeg 版本。跳跃很大,因为我们目前使用的是 ffmpeg 0.8,最新版本是 1.2。

在这些测试中,我使用了(让我说)我发现的很棒的软件包 here

首先,我尝试下载和构建 ffmpeg 1.2,当然我收到了很多警告和错误,关于函数和变量已弃用或不再存在。

为了平滑过渡,我尝试构建 ffmpeg 1.0,这是与 0.8 最接近的更高版本。我得到了下面列出的警告和错误列表。

我的问题如下:是否存在任何指南来帮助完成这些转换,在新版本中转换旧的 ffmpeg 范例/函数调用?我没有写,我不想逐行分析,如果可以将旧函数调用一对一转换为新函数调用,我会很高兴,变量也是如此。

这是警告和错误列表(我已经清理了它,因此每个错误/警告只有一个条目)

warning: 'AVStream* av_new_stream(AVFormatContext*, int)' is deprecated (declared at /ffmpeg/include/libavformat/avformat.h:1646) [-Wdeprecated-declarations]

warning: 'int avcodec_open(AVCodecContext*, AVCodec*)' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:3569) [-Wdeprecated-declarations]
error: 'avcodec_init' was not declared in this scope
warning: 'int avcodec_encode_video(AVCodecContext*, uint8_t*, int, const AVFrame*)' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:4272) [-Wdeprecated-declarations]

warning: 'AVCodecContext* avcodec_alloc_context()' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:3423) [-Wdeprecated-declarations]

warning: 'int avcodec_decode_audio3(AVCodecContext*, int16_t*, int*, AVPacket*)' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:3852) [-Wdeprecated-declarations]

warning: 'void av_close_input_file(AVFormatContext*)' is deprecated (declared at /ffmpeg/include/libavformat/avformat.h:1622) [-Wdeprecated-declarations]
error: 'av_open_input_file' was not declared in this scope
warning: 'int av_find_stream_info(AVFormatContext*)' is deprecated (declared at /ffmpeg/include/libavformat/avformat.h:1446) [-Wdeprecated-declarations]
error: 'av_set_parameters' was not declared in this scope

error: 'AVFormatContext' has no member named 'file_size'

error: 'URL_WRONLY' was not declared in this scope

error: 'url_fopen' was not declared in this scope
error: 'url_fclose' was not declared in this scope

error: 'SAMPLE_FMT_U8' was not declared in this scope
error: 'SAMPLE_FMT_S16' was not declared in this scope
error: 'SAMPLE_FMT_S32' was not declared in this scope
error: 'SAMPLE_FMT_FLT' was not declared in this scope

error: 'FF_I_TYPE' was not declared in this scope


编辑:

我正在看这些...
http://ffmpeg.org/doxygen/0.8/deprecated.html
http://ffmpeg.org/doxygen/0.9/deprecated.html
http://ffmpeg.org/doxygen/1.0/deprecated.html
http://ffmpeg.org/doxygen/1.1/deprecated.html
http://ffmpeg.org/doxygen/1.2/deprecated.html
http://ffmpeg.org/doxygen/trunk/deprecated.html

【问题讨论】:

标签: build ffmpeg upgrade deprecated


【解决方案1】:

看看here

URL_WRONLY -> AVIO_FLAG_WRITE
url_fopen -> avio_open
url_fclose -> avio_close

希望以上内容足以让您入门。


如果链接失效,这里是全文抄录:

我找到了一些关于如何移植旧代码的资源(hereherehere), 但由于这不是我需要的,所以我决定编写自己的版本。 所以,我们开始吧。

url_open()

此函数已更改为 avio_open。还有 url_close 重命名为avio_close。我在这里找到了这些信息。

av_new_stream()

从 FFMPEG 1.0.1 起仍支持此功能,但已标记 如已弃用。它将被 avformat_new_stream() 替换。认为 旧代码是:

AVStream *st = av_new_stream(oc, i);

修改后的代码应该是:

AVStream *st = avformat_new_stream(oc, NULL);
st->id = i

首先要小心检查 st 不为 NULL!

dump_format()

此函数已重命名为 av_dump_format()。

av_write_header()

替换为接受两个参数的 avformat_write_header() 而不是一个。传递 NULL 作为第二个参数以获得相同 旧功能的行为。

av_codec_open()

这个替换为av_codec_open2()。替换函数 接受三个参数而不是两个参数,但将 NULL 作为第三个参数 参数以获得与旧函数相同的行为。

avcodec_encode_audio()

替换为 avcodec_encode_audio2()。

av_set_parameters()

我无法很好地替换这个。首先,我发现 此功能没有替代品。但那是它还在的时候 在 FFMPEG 中可用,即使已弃用。然后,他们删除了它, 因此它必须有替换。在某些地方我发现 他们只禁用了它,而其他人则必须传递它的参数 到 avformat_write_header。最后我放弃了,因为我不需要 目前该部分代码的工作版本。因为在我的情况下 avformat_alloc_context() 被调用,然后是 av_set_parameters(),最后 我看到的是调用 avformat_alloc_output_context2() 代替 avformat_alloc_context() 的。但改变并非微不足道,所以我 跳过它。

SampleFormat

此枚举已重命名为 AVSampleFormat。

URL_WRONLY

此常量已被 AVIO_FLAG_WRITE 替换。

SAMPLE_FMT_U8, SAMPLE_FMT_S16, SAMPLE_FMT_S32, etc.

现在以 AV_ 为前缀,因此请使用 AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16等

【讨论】:

    【解决方案2】:

    正如 Gabi 指出的那样,该 URL 具有大部分已弃用常量的替换。

    但是,它缺少一些,因此我将发布您的输出表明完成此编译步骤所需的所有更改:

    avcodec_init -> avcodec_register_all
    av_open_input_file -> avformat_open_input
    

    这里可能值得注意的是,av_set_parameters 已被弃用并完全废弃,因此您现在应该在调用 avformat_open_input 时指定参数。

    AVFormatContext.file_size -> avio_size()
    URL_WRONLY -> AVIO_FLAG_WRITE
    url_fopen -> avio_open
    url_fclose -> avio_close
    SAMPLE_FMT_U8 -> AV_SAMPLE_FMT_U8
    SAMPLE_FMT_S16 -> AV_SAMPLE_FMT_S16
    SAMPLE_FMT_S32 -> AV_SAMPLE_FMT_S32
    SAMPLE_FMT_FLT -> AV_SAMPLE_FMT_FLT
    FF_I_TYPE -> AV_PICTURE_TYPE_I
    

    这应该涵盖您所有的实际错误。如果只是一个警告,那就花点时间弄清楚他们正在逐步采用什么!

    【讨论】:

    • 很遗憾,我无法奖励这两个答案。我会接受你的(更完整的)并奖励另一个(最大的相对贡献)非常感谢!
    • 哈哈,这有点不合常规,但有道理。谢谢!
    猜你喜欢
    • 2015-06-27
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2016-07-18
    • 2020-04-26
    • 1970-01-01
    相关资源
    最近更新 更多