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)
    
  • 相关阅读:
    记第一场省选
    POJ 2083 Fractal 分形
    CodeForces 605A Sorting Railway Cars 思维
    FZU 1896 神奇的魔法数 dp
    FZU 1893 内存管理 模拟
    FZU 1894 志愿者选拔 单调队列
    FZU 1920 Left Mouse Button 简单搜索
    FZU 2086 餐厅点餐
    poj 2299 Ultra-QuickSort 逆序对模版题
    COMP9313 week4a MapReduce
  • 原文地址:https://www.cnblogs.com/renhui/p/14212621.html
Copyright © 2011-2022 走看看