一、xvid、x264、ffmpeg源碼下載
鏈接:https://pan.baidu.com/s/13phSFrLqkGrKDGF3_a2cSA
提取碼:ls2s
二、交叉編譯
1. xvid
- tar zxvf xvidcore-1.3.3.tar.gz
- cd xvidcore/build/generic
- ./configure --prefix=/home/workspace/arm_soft/ --host=arm-hisiv100nptl-linux --target=arm-linux
- make -j 8
- make install
xvidcore-1.1.3這個版本有點問題,後面編譯ffmpeg的時候會提示找不到 libxvid,但還是記錄下。
make 出現錯誤
root@chenwr-pc:/home/workspace/soft/ffmpeg/xvidcore-1.1.3/build/generic# make
D: =build
C: ./decoder.c
cc1: error: unrecognized command line option "-freduce-all-givs"
編輯configure 搜索freduce 這兩處屏蔽掉
make -j 8
make install
2. x264
- tar jxvf last_x264.tar.bz2
- cd x264-snapshot-20161225-2245
- ./configure --prefix=/home/workspace/arm_soft --host=arm-hisiv100nptl-linux --enable-shared --disable-asm
- 修改config.mak
修改內容如下:
CC=gcc 改爲 CC=arm-hisiv100nptl-linux-gcc
LD=gcc -o 改爲 LD=arm-hisiv100nptl-linux-gcc -o
RANLIB=ranlib 改爲 RANLIB=arm-hisiv100nptl-linux-ranlib
STRIP=strip 改爲 STRIP=arm-hisiv100nptl-linux-strip - 修改common目錄下的cpu.c文件,詳情見錯誤記錄
- make -j 8
- make install
錯誤記錄:
make出現錯誤
libx264.a(cpu.o): In function `x264_cpu_num_processors':
cpu.c:(.text+0x44): undefined reference to `CPU_COUNT'
collect2: ld returned 1 exit status
解決辦法:
修改common目錄下的cpu.c文件,搜索關鍵字x264_cpu_num_processors,屏蔽CPU_COUNT,具體如圖所示。
編譯成功
3. ffmpeg
- tar jxvf ffmpeg-3.0.2.tar.bz2
- cd ffmpeg-3.0.2/
- ./configure --prefix=/home/workspace/arm_soft/ffmpeg --disable-static --enable-shared --disable-debug --disable-asm --disable-ffplay --disable-ffprobe --disable-ffserver --enable-small --disable-doc --enable-demuxer=rtsp --enable-parser=h264 --enable-cross-compile --enable-libx264 --enable-libxvid --enable-nonfree --enable-gpl --arch=arm --target-os=linux --cross-prefix=arm-hisiv100nptl-linux- --extra-cflags=-I/home/workspace/arm_soft/include --extra-ldflags=-L/home/workspace/arm_soft/lib
- make -j 8
- make install
錯誤記錄:
libavcodec/libx264.c: In function 'X264_frame':
libavcodec/libx264.c:271: error: 'x264_bit_depth' undeclared (first use in this function)
libavcodec/libx264.c:271: error: (Each undeclared identifier is reported only once
libavcodec/libx264.c:271: error: for each function it appears in.)
libavcodec/libx264.c:371: warning: 'coded_frame' is deprecated (declared at libavcodec/avcodec.h:2945)
libavcodec/libx264.c:381: warning: 'coded_frame' is deprecated (declared at libavcodec/avcodec.h:2945)
libavcodec/libx264.c: In function 'X264_init':
libavcodec/libx264.c:539: warning: 'chromaoffset' is deprecated (declared at libavcodec/avcodec.h:2210)
libavcodec/libx264.c:540: warning: 'chromaoffset' is deprecated (declared at libavcodec/avcodec.h:2210)
libavcodec/libx264.c:553: warning: 'scenechange_threshold' is deprecated (declared at libavcodec/avcodec.h:2108)
libavcodec/libx264.c:554: warning: 'scenechange_threshold' is deprecated (declared at libavcodec/avcodec.h:2108)
libavcodec/libx264.c:600: warning: 'noise_reduction' is deprecated (declared at libavcodec/avcodec.h:2112)
libavcodec/libx264.c:601: warning: 'noise_reduction' is deprecated (declared at libavcodec/avcodec.h:2112)
libavcodec/libx264.c:610: warning: 'b_frame_strategy' is deprecated (declared at libavcodec/avcodec.h:1830)
libavcodec/libx264.c:611: warning: 'b_frame_strategy' is deprecated (declared at libavcodec/avcodec.h:1830)
libavcodec/libx264.c:618: warning: 'coder_type' is deprecated (declared at libavcodec/avcodec.h:2576)
libavcodec/libx264.c:619: warning: 'coder_type' is deprecated (declared at libavcodec/avcodec.h:2576)
libavcodec/libx264.c:715: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:717: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:719: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:721: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:723: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c: In function 'X264_init_static':
libavcodec/libx264.c:898: error: 'x264_bit_depth' undeclared (first use in this function)
make: *** [libavcodec/libx264.o] Error 1
make: *** Waiting for unfinished jobs....
定位到報錯的源碼位置
在我交叉編譯x264 make install成功的/home/workspace/arm_soft目錄下搜索x264_bit_depth,發現有定義,但是是大寫的。
原來是海思編譯器的問題,沒有去區分大小寫,於是在x264_config.h新增一個小寫的宏定義
編譯成功。
ffmpeg configure選項說明,轉發了一個整理很不錯的博客,參考該博客,根據自己實際需求去配置相關編解碼器就好了。
ffmpeg configure配置選項 - chenwr2018的博客 - CSDN博客
三、驗證
將ffmpeg x264 xvid 相關的include與lib拷貝到設備上。由於我沒有裁剪,並且設備根目錄空間有限,暫時拷貝到U盤,先測試下轉碼功能是否ok。
設置好環境變量:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/udisk/ffmpeg/lib
export PATH=$PATH:/mnt/udisk/ffmpeg/include:/mnt/udisk/ffmpeg/bin
在開發板進行測試
成功壓縮視頻文件