日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ffmpeg 新老接口问题及对照集锦

發布時間:2023/12/10 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ffmpeg 新老接口问题及对照集锦 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ffmpeg源碼包里面有個apichangs文檔,里面有各種接口改變的記錄,如果你發現接口不能用了,可以去搜索那個文檔,可以找到對應的新接口,然后到新接口對應的頭文件中找到說明文字


網上很多關于ffmpeg (libav)的資料都是N年以前的,而事實上ffmpeg數年來一直在“以時俱進”,因此無論是一些新手,或者號稱為老手的人,有時候難免出頭痛。。。。。。


為了解決大家的頭痛的問題,特列一個貼子,把ffmpeg相關的一些常見的、版本的問題列舉出來,供大家參考,同時也請大家一起補充。

1) 不認識guess_format.
解決:??#define guess_format??av_guess_format
接口不變。

2) 不認識av_alloc_format_context
解決:??#define? ?av_alloc_format_context??avformat_alloc_output_context
接口調整。

3) 不認識CODEC_TYPE_VIDEO 和 CODEC_TYPE_AUDIO
解決:
#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO

4) 不認識audio_resample_init
解決:#define audio_resample_init av_audio_resample_init
接口調整。

5) avcodec_decode_video 到 avcodec_decode_video2接口調整
舊代碼:
  • len = avcodec_decode_video(c, (short *)outbuf, &out_size, inbuf_ptr, size);
  • 復制代碼 新代碼:
  • av_init_packet(&pkt);
  • pkt.data = (unsigned char*)inbuf_ptr;
  • pkt.size = size;
  • len = avcodec_decode_video2(c, &tmpFrame, &got_picture, &pkt);
  • 復制代碼
    av_open_input_file
    /opt/workspace/android/EasyPlayer/jni/EasyPlayer/EasyPlayer.cpp:483: warning: 'int av_open_input_file(AVFormatContext**, const char*, AVInputFormat*, int, AVFormatParameters*)' is deprecated (declared at /opt/workspace/android/EasyPlayer/jni/EasyPlayer/../include/libavformat/avformat.h:1480)
    新接口:
  • #ifdef _FFMPEG_0_6__
  • ? ? if(av_open_input_file(&ffmpeg_fields.pFormatCtx, _filePath, NULL, 0, NULL) != 0)
  • #else
  • ? ? if (avformat_open_input(&ffmpeg_fields.pFormatCtx, _filePath, NULL, NULL) != 0)
  • #endif

  • 復制代碼 av_find_stream_info
    /opt/workspace/android/EasyPlayer/jni/EasyPlayer/EasyPlayer.cpp:494: warning: 'int av_find_stream_info(AVFormatContext*)' is deprecated (declared at /opt/workspace/android/EasyPlayer/jni/EasyPlayer/../include/libavformat/avformat.h:1526)
    新接口:
  • #ifdef _FFMPEG_0_6__
  • ? ?? ???if(av_find_stream_info(ffmpeg_fields.pFormatCtx) < 0)
  • #else
  • ? ?? ???if (avformat_find_stream_info(ffmpeg_fields.pFormatCtx, NULL) < 0)
  • #endif
  • 復制代碼 av_close_input_file

    /opt/workspace/android/EasyPlayer/jni/EasyPlayer/EasyPlayer.cpp:522: warning: 'void av_close_input_file(AVFormatContext*)' is deprecated (declared at /opt/workspace/android/EasyPlayer/jni/EasyPlayer/../include/libavformat/avformat.h:1706)

    新接口:
  • #ifdef _FFMPEG_0_6__
  • ? ?? ???av_close_input_file(ffmpeg_fields.pFormatCtx);
  • #else
  • ? ?? ???avformat_close_input(&ffmpeg_fields.pFormatCtx);
  • #endif

  • 復制代碼 注意,這個是個2級指針。

    avcodec_open2
    新出來的avcodec_open2接口支持一些編解碼特性的指定。
    #ifdef __FFMPEG_0_6__
    ? ? if (avcodec_open(ffmpeg_video.codec_ctx, ffmpeg_video.codec) < 0)
    #else
    ? ? if (avcodec_open2(ffmpeg_video.codec_ctx, ffmpeg_video.codec, NULL) < 0)
    #endif

    avcodec_init

    /opt/workspace/android/EasyIPCam/jni/libeasycodec/EasyCodec.cpp:20: warning: 'void avcodec_init()' is deprecated (declared at /opt/workspace/android/EasyIPCam/jni/libeasycodec/../3rdparty/libavcodec/avcodec.h:3932)

    這個function已經不再需要了,當你調用avcodec_register()或者 avcodec_register_all()時,ffmpeg會自動調用它。所以放心大膽的移除掉就可以了。

    url_fclose url_fopen url_fseek等等

    /opt/workspace/android/EasyIPCam/jni/libeasycodec/EasyCodec.cpp:67: warning: 'int url_fclose(AVIOContext*)' is deprecated (declared at /opt/workspace/android/EasyIPCam/jni/libeasycodec/../3rdparty/libavformat/avio.h:324)
    這一系統的接口都只需要在前面加一個avio_的前綴就可以了,如:avio_close()。

    avcodec_alloc_context()

    /opt/workspace/android/EasyIPCam/jni/libeasycodec/EasyCodec.cpp:111: warning: 'AVCodecContext* avcodec_alloc_context()' is deprecated (declared at /opt/workspace/android/EasyIPCam/jni/libeasycodec/../3rdparty/libavcodec/avcodec.h:4025)

    使用最新接口:avcodec_alloc_context3()
  • ? ? m_pACodec = avcodec_find_encoder((CodecID)nCodecID);
  • ? ? if(!m_pACodec) return false;
  • ? ? m_pAContext? ?? ?? ?? ?? ?? ???= avcodec_alloc_context3(m_pACodec);


  • 復制代碼 av_get_bits_per_sample_format

    /opt/workspace/android/EasyIPCam/jni/libeasycodec/EasyCodec.cpp:143: warning: 'int av_get_bits_per_sample_format(AVSampleFormat)' is deprecated (declared at /opt/workspace/android/EasyIPCam/jni/libeasycodec/../3rdparty/libavcodec/avcodec.h:4529)
    新接口改為av_get_bytes_per_sample(反正音頻bits per sample是8的倍數,不是8就是16,直接用byte比用bit更好)

    audio_resample_init

    /opt/workspace/android/EasyIPCam/jni/libeasycodec/EasyCodec.cpp:157: error: 'audio_resample_init' was not declared in this scope
    新接口:av_audio_resample_init,原先我以為ffmpeg要支持超過2 channels的resample,后來一看resample.c里的實現,結果發現還是只能支持mono和stereo
    多出來的幾個參數,給填default值:
  • ? ?? ?? ?? ?? ? AV_SAMPLE_FMT_S16,
  • ? ?? ?? ?? ?? ? AV_SAMPLE_FMT_S16,
  • ? ?? ?? ?? ?? ? TAPS, 10, 0, 0.8

  • 復制代碼 詳見resample.c,或者參考RTSPPlayer中的easyffmpeg.cpp.

    PKT_FLAG_KEY
    沒什么好說的,直接在前面加個AV_的前綴:AV_PKT_FLAG_KEY

    av_alloc_format_context

    /opt/workspace/android/EasyIPCam/jni/libeasycodec/EasyCodec.cpp:722: error: 'av_alloc_format_context' was not declared in this scope
    這個前面兩位同仁有提到不同,但不說怎么個不同法,實在可恨,我直接寫個例子:
  • avformat_alloc_output_context2(&m_pFormatCtx, pOutputFmt, "avi", pFileName);
  • 復制代碼

    總結

    以上是生活随笔為你收集整理的ffmpeg 新老接口问题及对照集锦的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。