😁博客主页😁:🚀https://blog.csdn.net/wkd_007🚀
🤑博客内容🤑:🍭嵌入式开发、Linux、C语言、C++、数据结构、音视频🍭
🤣本文内容🤣:🍭介绍音频编码opus的相关开源库编译🍭
😎金句分享😎:🍭子曰:古者言之不出,耻躬之不逮也。 ——《论语·里仁篇》,意思是,古代的君子从不轻易发表言论,他们以说了二做不到为耻。🍭
🎄一、opus-1.4
✨1.1 opus库下载
本文下载的是:opus-1.4.tar.gz
✨1.2 opus库普通编译
./configure --prefix=`pwd`/result_gcc
make && make install
✨1.3 opus库交叉编译
交叉编译:
tar zxvf opus-1.4.tar.gz
cd opus-1.4/
./configure --prefix=`pwd`/result_v300 CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux
make && make install
运行demo:
opus_demo 在 opus-1.4/.libs/ 文件夹里
#opus编码
# ./opus_demo -e audio 48000 2 64000 48000Hz-16bit-2ch-ChengDu.pcm 48000Hz-16bit-2ch-ChengDu.opus
libopus 1.4
Encoding 48000 Hz input at 64.000 kb/s in auto bandwidth with 960-sample frames.
average bitrate: 57.447 kb/s
maximum bitrate: 127.600 kb/s
active bitrate: 57.470 kb/s
bitrate standard deviation: 8.813 kb/s
#opus解码
# ./opus_demo -d 48000 2 48000Hz-16bit-2ch-ChengDu.opus 48000Hz-16bit-2ch-ChengDu1.pcm
libopus 1.4
Decoding with 48000 Hz output (2 channels)
average bitrate: 57.447 kb/s
maximum bitrate: 127.600 kb/s
bitrate standard deviation: 8.813 kb/s
🎄二、libogg-1.3.5
✨2.1 libogg-1.3.5 库下载
libogg官网:https://www.xiph.org/
libogg开源地址:https://github.com/xiph/ogg
✨2.2 libogg-1.3.5 库交叉编译
tar zxvf libogg-1.3.5.tar.gz
cd libogg-1.3.5/
./configure --prefix=`pwd`/result_v300 CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux
make && make install
🎄三、opusfile-0.12
✨3.1 opusfile-0.12 库下载
opusfile-0.12 库下载地址:https://www.opus-codec.org/downloads/
✨2.2 opusfile-0.12 库交叉编译
首先,需要编译依赖库:opus-1.4、libogg-1.3.5、openssl-1.1.0g
1、交叉编译 opus-1.4,参见上文 1.3 opus库交叉编译
2、交叉编译 libogg-1.3.5,参见上文 2.2 libogg-1.3.5 库交叉编译
3、交叉编译 openssl-1.1.0g
tar zxf openssl-1.1.0g.tar.gz
cd openssl-1.1.0g/
./config no-asm shared no-async --prefix=`pwd`/result_v300 --cross-compile-prefix=arm-hisiv300-linux-
# 删除 -m64
sed -i 's/-m64//' Makefile
#添加 CFLAGS+=-mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations
sed -i '/CFLAGS=-DDSO_DLFCN/a\CFLAGS+=-mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mno-unaligned-access -fno-aggressive-loop-optimizations' Makefile
make && make install
4、交叉编译opusfile-0.12:
tar zxvf opusfile-0.12.tar.gz
cd opusfile-0.12/
# DEPS_CFLAGS、DEPS_LIBS指定依赖库libogg的路径,否则会报错
./configure --prefix=`pwd`/result_v300 CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux DEPS_CFLAGS="-I`pwd`/../libogg-1.3.5/result_v300/include/" DEPS_LIBS="`pwd`/../libogg-1.3.5/result_v300/lib/" CFLAGS="-I`pwd`/../libogg-1.3.5/result_v300/include/ -L`pwd`/../libogg-1.3.5/result_v300/lib/ -I`pwd`/../opus-1.4/result_v300/include/opus -L`pwd`/../opus-1.4/result_v300/lib/ -I`pwd`/../openssl-1.1.0g/result_v300/include/ -L`pwd`/../openssl-1.1.0g/result_v300/lib/ -lssl -lcrypto -lopus -logg"
make && make install
✨2.2 opusfile-0.12 库交叉编译问题解决
问题一:./configure 报错
./configure 报错:
configure: error: Package requirements (ogg >= 1.3 opus >= 1.0.1) were not met:
No package 'ogg' found
No package 'opus' found
原因:检测依赖库时,没有找到依赖的库 ogg、opus;
解决:通过DEPS_CFLAGS、DEPS_LIBS指定依赖的ogg头文件、ogg库文件。
问题二:make 报错
make 报错:
.../bin/ld: warning: libssl.so.1.1, needed by ./.libs/libopusurl.so, not found (try using -rpath or -rpath-link)
.../bin/ld: warning: libcrypto.so.1.1, needed by ./.libs/libopusurl.so, not found (try using -rpath or -rpath-link)
collect2: error: ld returned 1 exit status
原因:链接时,没找到 libssl.so.1.1、libcrypto.so.1.1
解决:通过 CFLAGS=“-lssl -lcrypto” 指定链接的库文件名
🎄四、opus-tools-0.2
✨4.1 opus-tools-0.2相关库下载
opus-tools-0.2相关库:libopusenc-0.2.1
、opus-tools-0.2.tar.gz
、
下载地址:https://www.opus-codec.org/downloads/
✨4.2 opus-tools-0.2库交叉编译
1、交叉编译 opus-1.4,参见上文 1.3 opus库交叉编译
2、交叉编译 libogg-1.3.5,参见上文 2.2 libogg-1.3.5 库交叉编译
3、交叉编译 opusfile-0.12,参见上文 2.2 opusfile-0.12 库交叉编译
4、交叉编译 libopusenc-0.2.1
tar zxf libopusenc-0.2.1.tar.gz
cd libopusenc-0.2.1/
./configure --prefix=`pwd`/result_v300 CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux DEPS_CFLAGS="-I`pwd`/../opus-1.4/result_v300/include/" DEPS_LIBS="-L`pwd`/../opus-1.4/result_v300/lib/" CFLAGS="-I`pwd`/../opus-1.4/result_v300/include/opus -L`pwd`/../opus-1.4/result_v300/lib/ -lopus"
make && make install
问题:make报错
/home/samba/00_thirdLib/001_opus/libopusenc-0.2.1/../opus-1.4/result_v300/include/: file not recognized: Is a directory
collect2: error: ld returned 1 exit status
原因:DEPS_CFLAGS指定路径时,没加-I
5、交叉编译
下载:https://xiph.org/flac/
tar xf flac-1.4.3.tar.xz
cd flac-1.4.3/
./configure --prefix=`pwd`/result_v300 CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux CFLAGS="-I`pwd`/../libogg-1.3.5/result_v300/include/ -L`pwd`/../libogg-1.3.5/result_v300/lib/ -logg"
6、交叉编译:opus-tools-0.2
tar zxvf opus-tools-0.2.tar.gz
cd opus-tools-0.2/
./configure --prefix=`pwd`/result_v300 CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux OGG_CFLAGS="-I`pwd`/../libogg-1.3.5/result_v300/include/" OGG_LIBS="-L`pwd`/../libogg-1.3.5/result_v300/lib/ -logg" OPUS_CFLAGS="-I`pwd`/../opus-1.4/result_v300/include/opus" OPUS_LIBS="-L`pwd`/../opus-1.4/result_v300/lib/ -lopus" OPUSFILE_CFLAGS="-I`pwd`/../opusfile-0.12/result_v300/include/opus" OPUSFILE_LIBS="-L`pwd`/../opusfile-0.12/result_v300/lib/ -lopusfile" OPUSURL_CFLAGS="-I`pwd`/../opusfile-0.12/result_v300/include/" OPUSURL_LIBS="-L`pwd`/../opusfile-0.12/result_v300/lib/ -lopusurl" LIBOPUSENC_CFLAGS="-I`pwd`/../libopusenc-0.2.1/result_v300/include/opus" LIBOPUSENC_LIBS="-L`pwd`/../libopusenc-0.2.1/result_v300/lib/ -lopusenc" FLAC_CFLAGS="-I`pwd`/../flac-1.4.3/result_v300/include/" FLAC_LIBS="-L`pwd`/../flac-1.4.3/result_v300/lib/ -lFLAC"
CFLAGS="-I`pwd`/../libogg-1.3.5/result_v300/include/ -L`pwd`/../libogg-1.3.5/result_v300/lib/ -logg -I`pwd`/../opus-1.4/result_v300/include/opus -L`pwd`/../opus-1.4/result_v300/lib/ -logg -I`pwd`/../libopusenc-0.2.1/result_v300/include/opus -L`pwd`/../libopusenc-0.2.1/result_v300/lib/"
make && make install
✨4.2 opus-tools-0.2 使用
opus-tool有四个工具:
opusdec
:将 opus 文件转成 wav 文件opusenc
:将 wav 文件转成 opus 文件opusinfo
:查看 opus 编码的 ogg 封装格式文件的信息;opusrtp
:可以从opus的抓包文件中提取出来opus音频,opusrtp输出的是已经封装到ogg中的音频。
使用下面命令可以将 wav 的音频转成 opus 的:
opusenc test.wav test.opus
下面命令将 opus 的音频转成 wav 的:
opusdec test.opus test.wav
另外,如果想在Ubuntu使用opusenc 命令,可通过apt安装:sudo apt install opus-tools
。
🎄五、总结
本文介绍 opus-1.4、libogg-1.3.5、opusfile-0.12、opus-tools-0.2 的交叉编译过程,以及问题解决。
如果文章有帮助的话,点赞👍、收藏⭐,支持一波,谢谢 😁😁😁