ffmpeg 新老接口问题及对照集锦
生活随笔
收集整理的這篇文章主要介紹了
ffmpeg 新老接口问题及对照集锦
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ffmpeg源碼包里面有個(gè)apichangs文檔,里面有各種接口改變的記錄,如果你發(fā)現(xiàn)接口不能用了,可以去搜索那個(gè)文檔,可以找到對(duì)應(yīng)的新接口,然后到新接口對(duì)應(yīng)的頭文件中找到說(shuō)明文字
網(wǎng)上很多關(guān)于ffmpeg (libav)的資料都是N年以前的,而事實(shí)上ffmpeg數(shù)年來(lái)一直在“以時(shí)俱進(jìn)”,因此無(wú)論是一些新手,或者號(hào)稱(chēng)為老手的人,有時(shí)候難免出頭痛。。。。。。
為了解決大家的頭痛的問(wèn)題,特列一個(gè)貼子,把ffmpeg相關(guān)的一些常見(jiàn)的、版本的問(wèn)題列舉出來(lái),供大家參考,同時(shí)也請(qǐng)大家一起補(bǔ)充。
1) 不認(rèn)識(shí)guess_format.
解決:??#define guess_format??av_guess_format
接口不變。
2) 不認(rèn)識(shí)av_alloc_format_context
解決:??#define? ?av_alloc_format_context??avformat_alloc_output_context
接口調(diào)整。
3) 不認(rèn)識(shí)CODEC_TYPE_VIDEO 和 CODEC_TYPE_AUDIO
解決:
#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
4) 不認(rèn)識(shí)audio_resample_init
解決:#define audio_resample_init av_audio_resample_init
接口調(diào)整。
5) avcodec_decode_video 到 avcodec_decode_video2接口調(diào)整
舊代碼:
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)
新接口:
/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)
新接口:
/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)
新接口:
avcodec_open2
新出來(lái)的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)
這個(gè)function已經(jīng)不再需要了,當(dāng)你調(diào)用avcodec_register()或者 avcodec_register_all()時(shí),ffmpeg會(huì)自動(dòng)調(diào)用它。所以放心大膽的移除掉就可以了。
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)
這一系統(tǒng)的接口都只需要在前面加一個(gè)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()
/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的倍數(shù),不是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要支持超過(guò)2 channels的resample,后來(lái)一看resample.c里的實(shí)現(xiàn),結(jié)果發(fā)現(xiàn)還是只能支持mono和stereo
多出來(lái)的幾個(gè)參數(shù),給填default值:
PKT_FLAG_KEY
沒(méi)什么好說(shuō)的,直接在前面加個(gè)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
這個(gè)前面兩位同仁有提到不同,但不說(shuō)怎么個(gè)不同法,實(shí)在可恨,我直接寫(xiě)個(gè)例子:
總結(jié)
以上是生活随笔為你收集整理的ffmpeg 新老接口问题及对照集锦的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: FTP服务器和客户端源代码编写问题(ft
- 下一篇: 解决链接错误:error LNK2001