zoukankan      html  css  js  c++  java
  • FFmpeg 过时 Api 汇总整理

    在学习和使用FFmpeg的时候,我们经常会去查找很多资料并加以实践,但是目前存在一个问题困扰着不少刚接触音视频的同学,那就是FFmpeg的弃用API如何调整。
    我们知道FFmpeg中所谓的“被声明为已否决”就是因为函数或者结构体属性被标示为attribute_deprecated,很有可能在未来的版本中就删除了。所以我们最好的解决方案就是使用新的被推荐使用的函数、结构体等。

    下面是相关的API的汇总:

    1、AVStream::codec: 被声明为已否决

    旧版本:

    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
    ...
    pCodecCtx = pFormatCtx->streams[videoIndex]->codec;
    

    新版本:

    if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){
    ...
    pCodecCtx = avcodec_alloc_context3(NULL);  
    if (pCodecCtx == NULL)  
    {  
      printf("Could not allocate AVCodecContext 
    ");  
      return -1;  
    }  
     if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
      printf("Couldn't find audio stream information 
    ");
      return -1;
    }
    avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoIndex]->codecpar);  
    

    2、avcodec_encode_audio2:被声明为已否决

    旧版本:

    if (avcodec_encode_audio2(tmpAvCodecCtx, &pkt_out, frame, &got_picture) < 0)
    

    新版本:

    if(avcodec_send_frame(tmpAvCodecCtx, frame)<0 || (got_picture=avcodec_receive_packet(tmpAvCodecCtx, &pkt_out))<0)
    

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

    旧版本:

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

    新版本:

    #include "libavutil/imgutils.h"
    av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1)
    

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

    旧版本:
    avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
    

    新版本:

    av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);
    

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

    旧版本:

    ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet); 
    

    新版本:

    if(avcodec_send_packet(pCodecCtx, packet)<0 || (got_picture =avcodec_receive_frame(pCodecCtx, pFrame))<0)       {return -1}
    

    6、' avcodec_alloc_frame': 被声明为已否决

    旧版本:

    pFrame = avcodec_alloc_frame();
    

    新版本:

    pFrame = av_frame_alloc();
    

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

    旧版本:

    av_free_packet(packet);
    

    新版本:

    av_packet_unref(packet);
    

    8、avcodec_decode_audio4:被声明为已否决

    旧版本:

    int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *avpkt);
    

    新版本:

    if(avcodec_send_packet(pCodecCtxOut_Video, &pkt)<0 || (got_frame=avcodec_receive_frame(pCodecCtxOut_Video,picture))<0) {return -1}
    

    9、avcodec_encode_video2:被声明为已否决

    旧版本:

    if(avcodec_encode_video2(tmpAvCodecCtx, &pkt, picture, &got_picture)<0)
    

    新版本:

    if(avcodec_send_frame(tmpAvCodecCtx, picture)<0 || (got_picture=avcodec_receive_packet(tmpAvCodecCtx, &pkt))<0)
    
  • 相关阅读:
    移动SI[转]
    什么是云计算
    ToString()格式和用法大全[转]
    SQLJOIN之完全用法[转]
    DIV样式汇总
    CSS+DIV之强化background属性
    SQLserver中用convert函数转换日期格式
    session丢失与解决办法的资料
    div滤镜结合ajax,实现登录
    什么是ajax
  • 原文地址:https://www.cnblogs.com/renhui/p/14212621.html
Copyright © 2011-2022 走看看