FFmpeg編譯,以及常見錯誤解決


編譯

這里強烈推薦官網的編譯指南,少走一些環境問題,版本問題的彎路
FFmpeg編譯指南

這里不多說,照着做基本不會有太大問題

Demo測試

.
├── build.sh
├── include
├── lib
├── share
├── test
└── testFFmpeg.c

測試代碼 testFFmpeg.c

//testFFmpeg.c
#include <stdio.h>
#include <libavcodec/avcodec.h>

int main(int argc, char *argv[])
{
    printf("hello ffmpeg\n");
    avcodec_register_all();
    return 0;
}

開開心心的來編譯,結果

~/ffmpeg_build# sh -x build.sh 
+ pwd
+ FFMPEG=/root/ffmpeg_build
+ gcc -I/root/ffmpeg_build/include/ -L/root/ffmpeg_build/lib/ -lavformat -lavcodec -lavutil -lswresample -lz -llzma -lpthread -lm testFFmpeg.c -o test
testFFmpeg.c: In function ‘main’:
testFFmpeg.c:8:5: warning: ‘avcodec_register_all’ is deprecated [-Wdeprecated-declarations]
    8 |     avcodec_register_all();
      |     ^~~~~~~~~~~~~~~~~~~~
In file included from testFFmpeg.c:3:
/root/ffmpeg_build/include/libavcodec/avcodec.h:2767:6: note: declared here
 2767 | void avcodec_register_all(void);
      |      ^~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccQQlEf5.o: in function `main':
testFFmpeg.c:(.text+0x20): undefined reference to `avcodec_register_all'

錯誤已經很明顯了,undefined reference to avcodec_register_all

說法1:extern
網上絕大多數說法是,需要extern,因為ffmpeg是純C語言編寫的

extern "C" {
#include <libavcodec/avcodec.h>
}

但我不是C++,所以問題沒有解決

說法2:
添加更多鏈接

抱着試試的心態,還是不行.

最后看了這ffmpeg移植到dm365上,遇到undefined reference錯誤文章
用下面命令重新編譯了一下,居然成功了

gcc -o test testFFmpeg.c $(pkg-config --libs --cflags libavcodec)

說到底還是包的依賴問題,編譯真的復雜,搞了一下午


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM