背景

根据例程学习调用ffmpeg 库方法的时候,发现了一堆警告。

main.cpp:81:37: warning: ‘AVStream::codec’ is deprecated [-Wdeprecated-declarations]
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)

介绍

从FFmpeg 3.0 开始 , 使用了很多新接口,在一些基本用法上,编译会看见很多的warning,类似

“ warning: ‘AVStream::codec’ is deprecated (declared at  /usr/local/ffmpeg/include/libavformat/avformat.h:880)  [-Wdeprecated-declarations]

out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;”

avcodec_decode_video2()

原本的解码函数被拆解为两个函数avcodec_send_packet()avcodec_receive_frame()

具体用法如下:

old:

avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, pPacket);

new:


avcodec_send_packet(pCodecCtx, pPacket); avcodec_receive_frame(pCodecCtx, pFrame);

avcodec_encode_video2()

对应的编码函数也被拆分为两个函数avcodec_send_frame()和avcodec_receive_packet() 具体用法如下:

old:

avcodec_encode_video2(pCodecCtx, pPacket, pFrame, &got_picture);

new:

avcodec_send_frame(pCodecCtx, pFrame);

avcodec_receive_packet(pCodecCtx, pPacket);

avpicture_get_size()

现在改为使用av_image_get_size() 具体用法如下:

old:

avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);

new:

//最后一个参数align这里是置1的,具体看情况是否需要置1

av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);

avpicture_fill()

现在改为使用av_image_fill_arrays 具体用法如下:

old:

avpicture_fill((AVPicture *)pFrame, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);

new:

//最后一个参数align这里是置1的,具体看情况是否需要置1

av_image_fill_arrays(pFrame->data, pFrame->linesize, buffer,  AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height,1);

关于codec问题有的可以直接改为codecpar,但有的时候这样这样是不对的,所以我也还在探索,这里记录一个对pCodecCtx和pCodec赋值方式的改变

old:

pCodecCtx = pFormatCtx->streams[video_index]->codec;

pCodec = avcodec_find_decoder(pFormatCtx->streams[video_index]->codec->codec_id);

new:

pCodecCtx = avcodec_alloc_context3(NULL);

avcodec_parameters_to_context(pCodecCtx,pFormatCtx->streams[video_index]->codecpar);

pCodec = avcodec_find_decoder(pCodecCtx->codec_id);

PIX_FMT_YUV420P -> AV_PIX_FMT_YUV420P

'AVStream::codec': 被声明为已否决:

old:

if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){

new:

if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){

'AVStream::codec': 被声明为已否决:

old:

pCodecCtx = pFormatCtx->streams[videoindex]->codec;

new:

pCodecCtx = avcodec_alloc_context3(NULL);

avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);

'avpicture_get_size': 被声明为已否决:

old:

avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height)

new:

#include "libavutil/imgutils.h"

av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1)

'avpicture_fill': 被声明为已否决:

old:

avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);

new:

av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize, out_buffer, AV_PIX_FMT_YUV420P,

pCodecCtx->width, pCodecCtx->height, 1);

'avcodec_decode_video2': 被声明为已否决:

old:

ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture,  packet); //got_picture_ptr Zero if no frame could be decompressed

new:

ret = avcodec_send_packet(pCodecCtx, packet);

got_picture = avcodec_receive_frame(pCodecCtx, pFrame); //got_picture = 0 success, a frame was returned

//注意:got_picture含义相反

或者:

int ret = avcodec_send_packet(aCodecCtx, &pkt);

if (ret != 0)

{

prinitf("%s/n","error");

return;

}

while( avcodec_receive_frame(aCodecCtx, &frame) == 0){

//读取到一帧音频或者视频

//处理解码后音视频 frame

}

'av_free_packet': 被声明为已否决:

old:

av_free_packet(packet);

new:

av_packet_unref(packet);

avcodec_decode_audio4:被声明为已否决:

old:

result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt);

new:

int ret = avcodec_send_packet(dec_ctx, &enc_pkt);

if (ret != 0) {

    prinitf("%s/n","error");

}

while( avcodec_receive_frame(dec_ctx, &out_frame) == 0){

    //读取到一帧音频或者视频

    //处理解码后音视频 frame
}

error: ‘avcodec_alloc_frame’ was not declared in this scope

old:

pFrame = avcodec_alloc_frame();

new:

pFrame = av_frame_alloc();

avpicture_get_size:被声明为已否决:

old:

numBytes = avpicture_get_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);

new:

/**
* @deprecated use av_image_get_buffer_size() instead.
*/
attribute_deprecated
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);

‘av_close_input_file’ was not declared in this scope

old :

av_close_input_file(pFormatCtx);

new:

avformat_close_input(&pFormatCtx);

FFmpeg新旧接口对照使用一览的更多相关文章

  1. MapReduce简述、工作流程及新旧API对照

    什么是MapReduce? 你想数出一摞牌中有多少张黑桃.直观方式是一张一张检查而且数出有多少张是黑桃. MapReduce方法则是: 1. 给在座的全部玩家中分配这摞牌. 2. 让每一个玩家数自己手 ...

  2. ffmpeg新老接口对比

    http://blog.csdn.net/leixiaohua1020/article/details/41013567

  3. Hadoop日记Day15---MapReduce新旧api的比较

    我使用hadoop的是hadoop1.1.2,而很多公司也在使用hadoop0.2x版本,因此市面上的hadoop资料版本不一,为了扩充自己的知识面,MapReduce的新旧api进行了比较研究. h ...

  4. [转帖]InfluxDB 1.2.0安装及新旧版本的注意事项

    InfluxDB 1.2.0安装及新旧版本的注意事项 http://haibing.org/245?zwlqby=npztq3 挺好的文章 很好的解决了 上一个文档里面 关于 web admin 的问 ...

  5. Android新旧版本Notification

    Android新旧版本Notification 在notification.setLatestEventInfo() 过时了 以前: NotificationManager mn = (Notific ...

  6. Matlab神经网络函数newff()新旧用法差异

    摘要 在Matlab R2010a版中,如果要创建一个具有两个隐含层.且神经元数分别为5.3的前向BP网络,使用旧的语法可以这样写: net1 = newff(minmax(P), [5 3 1]); ...

  7. [ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]

    Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou ...

  8. Flex布局新旧混合写法详解(兼容微信)

    原文链接:https://www.usblog.cc/blog/post/justzhl/Flex布局新旧混合写法详解(兼容微信) flex是个非常好用的属性,如果说有什么可以完全代替 float 和 ...

  9. Surface Pro 4 和 Surface Book 使用名为 Surface UEFI(统一可扩展固件接口)的新固件接口

    Surface Pro 4 和 Surface Book 使用名为 Surface UEFI(统一可扩展固件接口)的新固件接口.Surface UEFI 提供新功能,如启动更快速.安全性更高.可替换 ...

  10. 浅谈 angular新旧版本问题

    一直在学习angularJs,之前用的版本比较老,前些天更新了一下angularJs的版本,然后发现了一些问题,希望和大家分享一下. 在老的版本里控制器直接用函数定义就可以 比如: 在angularJ ...

随机推荐

  1. CF1872G

    题意:一个正整数序列,\(a[i] < 10^9\),求 \(l\),\(r\),最大化 \[\sum_{i = 1}^{l - 1} a[i] + \prod_{i = l}^r a[i] + ...

  2. sqli-labs-master 导入导出 + 第七关

    1.load_file()导出文件 load_file(file_name):读取文件并返回该文件内容作为一个字符串. 使用条件: A:必须有权限读取并且文件完全可读 B:预读取文件必修在服务器上 C ...

  3. 智能体Agent-书生浦语大模型实战营学习笔记6&大语言模型10

    大语言模型学习:10.智能体Agent 书生浦语大模型实战营学习笔记6 定义 即P(感知)-> P(规划)->A(行动).类似人类「做事情」的过程,Agent的核心功能,可以归纳为三个步骤 ...

  4. github无法push?看这篇文章就够了

    参考文章: https://mp.weixin.qq.com/s/56Dp3pM0BMyH2GZMGEsmCQ

  5. DNS(4) -- dns功能实现-配置正向解析和反向解析以及DNS递归查询示例

    目录 1 DNS配置示例 1.1 DNS解析类型 1.2 配置正向解析 1.3 配置反向解析 1.4 DNS递归查询 1.4.1 开启递归查询 1.4.2 关闭递归查询 1 DNS配置示例 1.1 D ...

  6. uni-app上使用leaflet地图的解决方案

    在uni-app上自带有map组件,但是那个组件功能太弱,很多高级用法很难实现.用npm添加leaflet呢,又各种报错. 偶然和朋友聊起,可以用html来实现leaflet地图,然后用webview ...

  7. gpu机器没有开启ipv6

    参考: https://blog.csdn.net/asdfaa/article/details/137884414 检查系统是否支持 IPv6,查看被禁用了 在启用 IPv6 之前,首先要确保您的系 ...

  8. 【u8】二开生成的专用采购发票结算后显示结算标志但是没有生成结算单的问题

    在表体 purbillvouchs 里有个字段 upsotype 上游单据类型 不能是空,如果是代管生成的发票要填写'vmiused', 如果是普通生成的发票要填写rd,还要写上 入库单号也就是普通挂 ...

  9. Flask源码阅读

    上下文篇 整个Flask生命周期中都依赖LocalStack()栈?.而LocalStack()分为请求上下文_request_ctx_stack和应用上下文_app_ctx_stack. _requ ...

  10. kubelet gc 源码分析

    代码 kubernetes 1.26.15 问题 混部机子批量节点NotReady(十几个,丫的重大故障),报错为: 意思就是 rpc 超了,节点下有太多 PodSandBox,crictl ps - ...