升级ffmpeg时处理ffmpeg库接口更改

Ant*_*nio 8 ffmpeg upgrade build deprecated

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

在这些测试中我使用的是(让我说)惊人的包,我觉得在这里.

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

为了平滑过渡,我尝试针对ffmpeg 1.0进行构建,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
Run Code Online (Sandbox Code Playgroud)


编辑:

我正在看看这些......
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

Gab*_*var 7

看看这里.

URL_WRONLY -> AVIO_FLAG_WRITE
url_fopen -> avio_open
url_fclose -> avio_close
Run Code Online (Sandbox Code Playgroud)

希望以上内容足以让你入门.


如果链接不存在,这里是全文转录:

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

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);
Run Code Online (Sandbox Code Playgroud)

修改后的代码应该是:

AVStream *st = avformat_new_stream(oc, NULL);
st->id = i
Run Code Online (Sandbox Code Playgroud)

小心首先检查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等.


cod*_*aku 7

正如Gabi所指出的那样,该URL具有大部分已弃用常量的替代品.

但是,它缺少一些,所以我将发布您的输出指示进行此编译步骤所需的所有更改:

avcodec_init -> avcodec_register_all
av_open_input_file -> avformat_open_input
Run Code Online (Sandbox Code Playgroud)

这里值得注意的是,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
Run Code Online (Sandbox Code Playgroud)

这应该涵盖你所有的实际错误.如果只是一个警告,那么花一些时间来弄清楚他们正在逐步采取什么措施!