当前位置: 首页 > 工具软件 > id3lib > 使用案例 >

音频文件ID3解析

空慈
2023-12-01
最近有个读取audio文件中的ID3信息的需求,下面说说过程。

一,编译库的过程记录:

1,最 开始使用Qt的QMediaPlayer类,发现必须播放了才能取出id3信息,这么脑残的设计,不能用;

2,后来使用ffmpeg,发现真他妈大啊,功能也绝对强大啊,源码解压出来都有795M,杀鸡用牛刀了,太笨重了,不用它。

3,再后来网友提供了一个taglib的开源库,很小,才3M,很开心,可悲催的是,mingW和Msys下死活编译不过,log如下,暂时未找到解决问题的方法,谁有解决办法告诉我,不胜感激!!
$ cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DCMAKE_INSTALL_PREFIX=/myinstall/taglib/ -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON  .
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: C:/Qt_with_mingGW_5.6/Qt5.6.1/Tools/mingw492_32/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_bb0f3\fast"
-- Check for working C compiler: C:/Qt_with_mingGW_5.6/Qt5.6.1/Tools/mingw492_32/bin/gcc.exe -- broken
CMake Error at C:/Qt_with_mingGW_5.6/Qt5.6.1/Tools/msys/myinstall/cmake/share/cmake-3.7/Modules/CMakeTestCCompiler.cmake:51 (message):
  The C compiler
  "C:/Qt_with_mingGW_5.6/Qt5.6.1/Tools/mingw492_32/bin/gcc.exe" is not able
  to compile a simple test program.
  It fails with the following output:
   Change Dir: C:/Users/TerryLee/Desktop/taglib-master/CMakeFiles/CMakeTmp
  Run Build Command:"nmake" "/NOLOGO" "cmTC_bb0f3\fast"
  Generator: execution of make failed.  Make command was: "nmake" "/NOLOGO"
  "cmTC_bb0f3\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/TerryLee/Desktop/taglib-master/CMakeFiles/CMakeOutput.log".
See also "C:/Users/TerryLee/Desktop/taglib-master/CMakeFiles/CMakeError.log".
(我最终用的还是这个taglib的开源库,在linux服务器或者mac上很容易就编过,接口调用也简单,值得推荐!)

4,再后来一个同事建议使用id3lib库,下载下来,configure和make也发现了一些错误,解决之后编译通过:
错误1:
    checking for string... yes
    checking iomanip.h usability... no
    checking iomanip.h presence... no
    checking for iomanip.h... no
    configure: error: Missing a vital header file for id3lib
解决方案:
     将configure文件中的iomanip.h改为iomanip即可configure通过
    
错误2:
    include/id3/id3lib_strings.h:87:72: error: 'memmove' was not declared in this scope
解决方案:
    在include/id3/id3lib_strings.h中添加#include <cstring>

错误3:
    include/id3/writers.h:171:5: error: '::memcpy' has not been declared
解决方案:
    在include/id3/writers.h中添加#include <cstring>


二,下面是编译使用id3lib-3.8.3中的例子 get_pic 来解出mp3文件中的专辑图片的过程:
1,例子路径是:id3lib-3.8.3/examples/get_pic.cpp

2,编译过程:
用g++进行编译:
lizekun@srv-pdk-compile:~/id3lib-3.8.3/examples$ g++ get_pic.cpp -I /home/local/ACTIONS/lizekun/my_install/id3/include/ -L/home/local/ACTIONS/lizekun/my_install/id3/lib -lid3
报错:
/home/local/ACTIONS/lizekun/my_install/id3/lib/libid3.so: undefined reference to `compress'
/home/local/ACTIONS/lizekun/my_install/id3/lib/libid3.so: undefined reference to `uncompress'
collect2: ld returned 1 exit status
解决办法:
因为看到 id3lib-3.8.3中有zlib文件夹,试一下链接上zlib,结果通过了:
lizekun@srv-pdk-compile:~/id3lib-3.8.3/examples$ g++ get_pic.cpp -I /home/local/ACTIONS/lizekun/my_install/id3/include/ -L/home/local/ACTIONS/lizekun/my_install/id3/lib -lid3 -lz

3,使用过程:
执行解析动作:
lizekun@srv-pdk-compile:~/id3lib-3.8.3/examples$./a.out Jive_Cool.mp3 ~/aa.png
报错:
./a.out: error while loading shared libraries: libid3-3.8.so.3: cannot open shared object file: No such file or directory
解决办法:
lizekun@srv-pdk-compile:~/id3lib-3.8.3/examples$export LD_LIBRARY_PATH=~/my_install/id3/lib/
再次 执行解析动作,成功
*** extracting picture to file "/home/local/ACTIONS/lizekun/aa.png"... done!

将aa.png拷贝到windows上查看,果然,一幅完整的封面图片就这样呈现在面前了,什么?你要其他的ID3信息,比如歌手,专辑名,时长等, 拜托,图片都parse出来了,其他的更简单了,庆祝一下吧!^_^

 类似资料: