ffmpeg 3.0 changes

從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;”

  1. avcodec_decode_video2()
    原本的解碼函數(shù)被拆解為兩個函數(shù)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);

  2. avcodec_encode_video2()
    對應的編碼函數(shù)也被拆分為兩個函數(shù)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);

  3. avpicture_get_size()
    現(xiàn)在改為使用av_image_get_size() 具體用法如下:
    old:
    avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
    new:
    //最后一個參數(shù)align這里是置1的,具體看情況是否需要置1
    av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);

  4. avpicture_fill()
    現(xiàn)在改為使用av_image_fill_arrays 具體用法如下:
    old:
    avpicture_fill((AVPicture *)pFrame, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
    new:
    //最后一個參數(shù)align這里是置1的,具體看情況是否需要置1
    av_image_fill_arrays(pFrame->data, pFrame->linesize, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height,1);

  5. 關(guān)于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);

  6. PIX_FMT_YUV420P -> AV_PIX_FMT_YUV420P

  7. 'AVStream::codec': 被聲明為已否決:
    old:
    if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
    new:
    if(pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){

  8. 'AVStream::codec': 被聲明為已否決:
    old:
    pCodecCtx = pFormatCtx->streams[videoindex]->codec;
    new:
    pCodecCtx = avcodec_alloc_context3(NULL);
    avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);

  9. '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)

  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);

  2. '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
    }

  3. 'av_free_packet': 被聲明為已否決:
    old:
    av_free_packet(packet);
    new:
    av_packet_unref(packet);

  4. 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
    }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容