如何使用mp3libmp3 id3v2lib用法

构建嵌入式Linux应用系统&——&mp3播放器&madplay的移植
我们的Linux系统开机时都会播放一首 mp3,这其中所用的播放器就是
madplay,下面我们介绍一下该播放器的详细移植过程。
说明:本文中所使用的交叉编译器版本为
arm-linux-gcc-3.4.5,为了还原一个真实的移植过程,本文从网络上搜索源代码开始。
目前madplay的官方网站是 ,透过该网站的介绍可以得知,它还需要
libmad和 libid3tag两个库,从该网站找到下载连接
这样我们就得到了移植 madplay所需要的关键的三个文件:
madplay-0.15.2b.tar.gz
libmad-0.15.1b.tar.gz
libid3tag-0.15.1b.tar.gz
它还会用到其他文件吗?只有天知道!一般都会遇到一些小麻烦,让我们继续吧。一般移植嵌入式应用软件的步骤是先在
PC上配置编译该软件并运行,以了解一下该软件的编译安装过程、用途、使用方法等。在PC上运行成功后,再将其移植到其它平台。现在我们就先在
PC上开始。
(1)建立工作目录,拷贝源代码包
在/work/system目录下建立
madplay目录,并以此为工作目录,并在该目录中建立以下子目录,以存放不同的文件:
#cd /work/system
#mkdir madplay
#cd madplay
#mkdir tarball src-x86 src-arm target-x86 target-arm
目录说明:tarball目录用来存放所有的源代码包,src-x86 目录用来存放 X86版本的所有源代码文件,
src-arm目录用来存放 ARM版本的所有源代码文件, target-x86 目录是 X86版本的安装目录,
target-arm目录是 ARM版本的安装目录。接下来把从网上下载到的源代码包放入 tarball目录:
(2)解压源代码包
#cd tarball
#for f in $(ls *.tar.gz); do tar xvzf $f &C ../src-86 ; done
(3)编译 madplay所依赖的库文件
a) libid3tag
#cd ../src-x86/libid3tag-0.15.1b
#./configure --prefix=/work/system/madplay/target-x86
#make install
#cd ../ libmad-0.15.1b
#./configure --prefix=/work/system/madplay/target-x86
#make install
若出现找不到zlib.h的错误,则是由于你的Linux机器上还未安装zlib库,请按照“详解制作根文件系统”一文所述安装zlib库到你的Linux机器。
以上过程完毕,将在 target-x86目录出现编译 madplay所依赖的库文件和头文件。
(4)编译安装 madplay
如果我们还是像刚才那样配置编译选项:
#cd madplay-0.15.2b
#./configure --prefix=/work/system/madplay/target-x86
将会出现如图错误:
提示找不到mad.h头文件。出现这样的错误提示,是因为madplay依赖于libmad库,因此在配置madplay的时候,它会查找相关依赖库的头文件mad.h。因为我们之前已经编译并安装了依赖库,所以只需要根据提示设置
CPPFLAGS环境变量,指向mad.h头文件所在的位置即可。采用如下参数重新配置:
#./configure --prefix=/work/system/madplay/target-x86
CPPFLAGS=-I/work/system /madplay/target-x86/include
运行结果如图所示:
提示找不到libmad库文件。出现这样的错误提示,是因为madplay依赖于libmad库,因此在配置madplay的时候,它会查找相关依赖库的库文件libmad.so。因为我们之前已经编译并安装了依赖库,所以只需要根据提示设置
LDFLAGS环境变量,指向libmad.so库文件所在的位置即可。因此再次修改配置参数如下:
./configure --prefix=/work/system/madplay/target-x86
CPPFLAGS=-I/work/system/madplay/target-x86/include
LDFLAGS=-L/work/system/madplay/target-x86/lib
执行结果如下:
这说明配置已经成功,生成了编译所需要的 Makefile文件,输入一下命令开始编译安装:
#make install
执行完毕,可执行文件将被安装在我们指定的目录/work/system/madplay/target-x86目录中:
#cd /work/system/madplay
#ls target-x86/bin
abxtest madplay
其中 abxtest是附加生成的测试程序,不必理会。
(5)测试 PC版的 madplay
拷贝一首 mp3文件到 madplay所在的目录,执行: #./madplay test.mp3。
如果你的声卡已经正确安装,就可以听到 mp3的声音了。
(6)构建编译脚本 build-x86
通过以上步骤,我们看到配置和编译不仅有一定的顺序,还需要注意一些安装细节,虽然这次编译通过了,但不免以后会忘记这个过程,特别是当程序更加复杂的时候。因此我们要养成好习惯,把整个过程构建为一个脚本,以后只要执行这个脚本就可以完成所有步骤了,如图所示是
PC版本 madplay的构建脚本,该脚本位于 madplay工作目录的根目录:
MADPLAY_DIR=$PWD
SRC_DIR=src-x86
TARGET_DIR=$MADPLAY_DIR/target-x86
tar xvzf ./tarball/libid3tag-0.15.1b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/libmad-0.15.1b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/madplay-0.15.2b.tar.gz -C $SRC_DIR
cd $SRC_DIR/libid3tag-0.15.1b
./configure --prefix=$TARGET_DIR
make install
cd $SRC_DIR/libmad-0.15.1b
./configure --prefix=$TARGET_DIR
make install
cd $SRC_DIR/madplay-0.15.2b
./configure --prefix=$TARGET_DIR CPPFLAGS=-I$TARGET_DIR/include
LDFLAGS=-L$TARGET_DIR/lib
make install
(7)构建并修正 ARM版本的编译脚本 build-arm
既然我们已经构建了一个简单易用的编译脚本,现在就可以通过对它稍作修改来进行交叉编译了,这就是通常所说的移植。简单的移植只要重新指定一下编译器就可以了,可以通过修改环境变量来实现。很多的移植所要修改的环境变量是
CC 编译器,系统默认为 gcc,需要修改为arm-linux-gcc
AR 库工具,用以创建和修改库,需要修改为arm-linux-ar
LD 链接器,系统默认为 LD,需要修改为arm-linux-ld
RANLIB 随机库创建器,系统默认为 ranlib,需要修改为arm-linux-ranlib
AS 汇编器,系统默认为 as,需要修改为arm-linux-as
NM 库查看工具,系统默认为 nm,需要修改为arm-linux-nm
还有一些不常用的其他环境变量,在此就不一一列举了。需要注意的是,并不是每个移植都需要做全面的环境变量修改,有些是不需要改的,这要根据实际情况,也就是系统提示信息来调整。
除了要修改编译器环境变量,我们还必须保证编译出来的应用程序(或者链接库)必须是运行在ARM平台上,而不是I386平台上。这一般需要在使用configure程序进行配置时,加入目标平台指定标识,一般的做法是
“./configure --host=arm-linux”,修改后的脚本如下:
MADPLAY_DIR=$PWD
SRC_DIR=src-arm
TARGET_DIR=$MADPLAY_DIR/target-arm
tar xvzf ./tarball/libid3tag-0.15.1b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/libmad-0.15.1b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/madplay-0.15.2b.tar.gz -C $SRC_DIR
export CC=arm-linux-gcc
cd $SRC_DIR/libid3tag-0.15.1b
./configure --host=arm-linux --prefix=$TARGET_DIR
CPPFLAGS=-I$TARGET_DIR/include LDFLAGS=-L$TARGET_DIR/lib
make install
cd $SRC_DIR/libmad-0.15.1b
./configure --host=arm-linux --prefix=$TARGET_DIR
make install
cd $SRC_DIR/madplay-0.15.2b
./configure --host=arm-linux --prefix=$TARGET_DIR
CPPFLAGS=-I$TARGET_DIR/include LDFLAGS=-L$TARGET_DIR/lib
make install
现在我们直接运行一下该脚本,看结果,如图:
根据提示,可以推断 libid3tag库没有被正确编译出来,再根据更上的提示信息,我们得知该库还依赖于一个叫做“
zlib”的库,为什么 PC版本的没有这个问题呢,是因为我们所使用的 PC
Linux系统中已经有了这个库,但运行在ARM平台上的zlib库还没有。因此我们从网上搜索到该库的源代码包,下载下来放到
tarball目录中,并在编译脚本中参考其他库在相应位置加入以下部分:
tar xvzf ./tarball/zlib-1.2.3.tar.gz -C $SRC_DIR
cd $SRC_DIR/zlib-1.2.3
./configure --prefix=$TARGET_DIR
make && make install
再次执行编译脚本,这次顺利编译通过,最后在 target-arm/bin目录中可以看到交叉编译生成的 madplay,使用
file命令检查一下,可见现在编译出来的madplay的确是运行在ARM平台上的。如图:
最后完整的编译脚本如下:
MADPLAY_DIR=$PWD
SRC_DIR=src-arm
TARGET_DIR=$MADPLAY_DIR/target-arm
tar xvzf ./tarball/libid3tag-0.15.1b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/libmad-0.15.1b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/madplay-0.15.2b.tar.gz -C $SRC_DIR
tar xvzf ./tarball/zlib-1.2.3.tar.gz -C $SRC_DIR
export CC=arm-linux-gcc
cd $SRC_DIR/zlib-1.2.3
./configure --prefix=$TARGET_DIR
make && make install
cd $SRC_DIR/libid3tag-0.15.1b
./configure --host=arm-linux --prefix=$TARGET_DIR
CPPFLAGS=-I$TARGET_DIR/include LDFLAGS=-L$TARGET_DIR/lib
make install
cd $SRC_DIR/libmad-0.15.1b
./configure --host=arm-linux --prefix=$TARGET_DIR
make install
cd $SRC_DIR/madplay-0.15.2b
./configure --host=arm-linux --prefix=$TARGET_DIR
CPPFLAGS=-I$TARGET_DIR/include LDFLAGS=-L$TARGET_DIR/lib
make install
(8)下载 madplay到开发板运行测试
把它以及依赖库下载到开发板,并作如下放置:
执行文件: madplay 放在 /usr/bin/目录
库文件:libid3tag.so.0、libid3tag.so.0.3.0、libmad.so.0、libmad.so.0.2.1放在/usr/lib目录。
执行结果如图所示:
特别说明:本文源自友善之臂qq2440v3开发板的配套文档,只是做了少量修改,可视为原文的转载。在此对友善之臂公司致谢。
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。114网址导航How To : Stream A Webcam From The Raspberry Pi – The Rantings and Ravings of a Madman
Advertisement
Advertisement from Maker Shed
Affiliate Links
PartSimCircuit Simulation Made Easy
A free CAD application for designing and manufacturing electronics hardware
Help Keep This Site Up
As we all know, hosting costs money. You can help me keep this site up and running by pressing on the button below :)
Recent Posts
© 2011Pages: 1/2
主题 : 使用lame库,转mp3,不支持64位编译,如何解决,请教,谢谢!
级别: 新手上路
可可豆: 37 CB
威望: 28 点
在线时间: 78(时)
发自: Web Page
使用lame库,转mp3,不支持64位编译,如何解决,请教,谢谢!&&&
现需求是跨平台的音频文件传输,希望能够使用mp3。
32位下,采用&& 此方法可用。但不支持64位。
此贴方法/questions/9207063/how-can-i-compile-lame-as-static-library-a-for-armv6-and-armv7-of-iphone,也试过,但会出现以上错误。
不知能否解决mp3 lame库64位的兼容问题,如果此库无法支持64位,有其他的办法转换mp3格式么??
级别: 新手上路
可可豆: 37 CB
威望: 28 点
在线时间: 78(时)
发自: Web Page
Last login: Tue Apr 15 15:14:45 on consoleris-MacBook-Pro:~ lixin$ cd /Users/lixin/Desktop/lameris-MacBook-Pro:lame lixin$ sudo -sPassword:bash-3.2# chmod a+x lamebuilderbash-3.2# ./lamebuildermkdir: build: File existsmake: *** No rule to make target `distclean'.
Stop.configure: WARNING: if you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be usedchecking build system type... i686-apple-darwin13.1.0checking host system type... arm-apple-darwin9checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for arm-apple-darwin9-strip... nochecking for strip... stripchecking for a thread-safe mkdir -p... ./install-sh -c -dchecking for gawk... nochecking for mawk... nochecking for nawk... nochecking for awk... awkchecking whether make sets $(MAKE)... yeschecking whether to enable maintainer-specific portions of Makefiles... nochecking for style of include used by make... GNUchecking for arm-apple-darwin9-gcc... /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i686checking whether the C compiler works... noconfigure: error: in `/Users/lixin/Desktop/lame':configure: error: C compiler cannot create executablesSee `config.log' for more detailsmake: *** No targets specified and no makefile found.
Stop.cp: libmp3lame/.libs/libmp3lame.a: No such file or directorymake: *** No rule to make target `distclean'.
Stop.configure: WARNING: if you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be usedchecking build system type... i686-apple-darwin13.1.0checking host system type... arm-apple-darwin9checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for arm-apple-darwin9-strip... nochecking for strip... stripchecking for a thread-safe mkdir -p... ./install-sh -c -dchecking for gawk... nochecking for mawk... nochecking for nawk... nochecking for awk... awkchecking whether make sets $(MAKE)... yeschecking whether to enable maintainer-specific portions of Makefiles... nochecking for style of include used by make... GNUchecking for arm-apple-darwin9-gcc... /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6checking whether the C compiler works... noconfigure: error: in `/Users/lixin/Desktop/lame':configure: error: C compiler cannot create executablesSee `config.log' for more detailsmake: *** No targets specified and no makefile found.
Stop.cp: libmp3lame/.libs/libmp3lame.a: No such file or directorymake: *** No rule to make target `distclean'.
Stop.configure: WARNING: if you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be usedchecking build system type... i686-apple-darwin13.1.0checking host system type... arm-apple-darwin9checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for arm-apple-darwin9-strip... nochecking for strip... stripchecking for a thread-safe mkdir -p... ./install-sh -c -dchecking for gawk... nochecking for mawk... nochecking for nawk... nochecking for awk... awkchecking whether make sets $(MAKE)... yeschecking whether to enable maintainer-specific portions of Makefiles... nochecking for style of include used by make... GNUchecking for arm-apple-darwin9-gcc... /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7checking whether the C compiler works... noconfigure: error: in `/Users/lixin/Desktop/lame':configure: error: C compiler cannot create executablesSee `config.log' for more detailsmake: *** No targets specified and no makefile found.
Stop.cp: libmp3lame/.libs/libmp3lame.a: No such file or directorymake: *** No rule to make target `distclean'.
Stop.configure: WARNING: if you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be usedchecking build system type... i686-apple-darwin13.1.0checking host system type... arm-apple-darwin9checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for arm-apple-darwin9-strip... nochecking for strip... stripchecking for a thread-safe mkdir -p... ./install-sh -c -dchecking for gawk... nochecking for mawk... nochecking for nawk... nochecking for awk... awkchecking whether make sets $(MAKE)... yeschecking whether to enable maintainer-specific portions of Makefiles... nochecking for style of include used by make... GNUchecking for arm-apple-darwin9-gcc... /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7schecking whether the C compiler works... noconfigure: error: in `/Users/lixin/Desktop/lame':configure: error: C compiler cannot create executablesSee `config.log' for more detailsmake: *** No targets specified and no makefile found.
Stop.cp: libmp3lame/.libs/libmp3lame.a: No such file or directoryfatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: build/* (No such file or directory)bash-3.2# 上面图片挂了,把错误直接贴上了, - -!!!!比较菜,实在搞不懂mp3格式怎么弄
级别: 新手上路
可可豆: 25 CB
威望: 24 点
在线时间: 93(时)
发自: Web Page
lz粘那么多字干嘛,no pic say a dick 造吗
级别: 侠客
UID: 279612
可可豆: 318 CB
威望: 398 点
在线时间: 507(时)
发自: Web Page
build settings 里面的 valid archivectures把arm64删掉看看
级别: 新手上路
可可豆: 25 CB
威望: 24 点
在线时间: 93(时)
发自: Web Page
lz粘那么多字干嘛,no pic say a dick 造吗
级别: 新手上路
可可豆: 47 CB
威望: 47 点
在线时间: 150(时)
发自: Web Page
发给邮件给我。我给你一个.a
级别: 新手上路
可可豆: 37 CB
威望: 28 点
在线时间: 78(时)
发自: Web Page
我发过邮件了哈,我邮箱,感谢!
级别: 新手上路
可可豆: 37 CB
威望: 28 点
在线时间: 78(时)
发自: Web Page
好像也不行啊,请问您有64位的lame.a么?
级别: 新手上路
可可豆: 37 CB
威望: 28 点
在线时间: 78(时)
发自: Web Page
已解决,谢谢
级别: 新手上路
可可豆: 25 CB
威望: 25 点
在线时间: 23(时)
发自: Web Page
麻烦一楼的大神 或者lz &也给我发一个 小弟邮箱是:
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
3*3+1 正确答案:10
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版

我要回帖

更多关于 id3lib 的文章

 

随机推荐