build - 升级 ffmpeg 时处理 ffmpeg 库接口(interface)更改

标签 build ffmpeg upgrade deprecated

我们目前正在尝试升级我们程序使用的 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

最佳答案

看看here .

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

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

万一链接失效,这里是全文成绩单:

I found some resources about how to port old code (here, here and here), but since it wasn't what I needed I decided to write my own version. So, here we go.

url_open()

This function has been changed to avio_open. There is also url_close which is renamed to avio_close. This information I found here.

av_new_stream()

This function is still supported as of FFMPEG 1.0.1 but it is marked as deprecated. It will be replaced with avformat_new_stream(). Suppose that the old code was:

AVStream *st = av_new_stream(oc, i);

the modified code should be:

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

Be careful to check first that st isn't NULL!

dump_format()

This function was renamed to av_dump_format().

av_write_header()

Replaced with avformat_write_header() that accepts two arguments instead of one. Pass NULL as the second argument to get identical behavior to the old function.

av_codec_open()

This one is replaced with av_codec_open2(). The replacement function accepts three arguments instead of two, but put NULL as a third argument to get the same behavior as the old function.

avcodec_encode_audio()

Replaced with avcodec_encode_audio2().

av_set_parameters()

I couldn't fine the replacement for this one. First, I've found that this function doesn't have replacement. But it was when it was still available in FFMPEG, even though deprecated. Then, they removed it, and thus it has to have replacement. In certain places I found that they only disabled it, on others that its parameters have to be passed to avformat_write_header. In the end, I gave up because I didn't need working version of that part of the code for now. Since in my case avformat_alloc_context() is called and then av_set_parameters(), last what I looked at was to call avformat_alloc_output_context2() instead of avformat_alloc_context(). But the change is not trivial so I skipped it.

SampleFormat

This enum has been renamed AVSampleFormat.

URL_WRONLY

This constant has been replaced with AVIO_FLAG_WRITE.

SAMPLE_FMT_U8, SAMPLE_FMT_S16, SAMPLE_FMT_S32, etc.

Those are prefixed now with AV_, so use AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16, etc.

关于build - 升级 ffmpeg 时处理 ffmpeg 库接口(interface)更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60901641/

相关文章:

android - Gradle 和插件更新在 Android Studio 中出现错误

python - 升级 Python 包 dateutil : Could not find a version

build - 是否有相当于 "Only show latest build status"的 Jenkins 管道?

jenkins - 有没有办法在声明性 Jenkins 管道中运行预结帐步骤?

php - FFMPEG - 转换所有上传到 MP4 的图像

batch-file - 使用 HandBrake 命令行将所有 avi 转换为 mp4 并在转换后删除的批处理脚本

dart - Flutter 错误 - 内核二进制格式版本无效(找到 4 个,预期为 6 个)

Python : Why do we need a build tool, 你对 CI 有什么建议?

java - 如何设置 Gradle 自定义 ant 任务类路径?

objective-c - iOS 中的 RTSP 流