Read ID3 tags without downloading the whole file

妖精的绣舞 提交于 2019-12-06 03:58:18

问题


Is it possible to read ID3 tags (Duration, Artist, title...) of an MP3 file without having to download the whole file?

I did a few tests and I was able to get the Artist and title tags with only downloading a few bytes of the MP3 file.. but I'm not sure if it's possible for Duration and other tags..

Thanks.


回答1:


I just find out that ffmpeg can read ID3 tags of a remote file without having to download the whole file:

root@local1:/# ffmpeg -i http://physics.ujep.cz/~mmaly/mp3/Mozart/Mass_in_C_Minor_New_by_Levin/sbory_vyssi_kvalita/01_Kyrie.mp3
FFmpeg version 0.6-4:0.6-2ubuntu6, Copyright (c) 2000-2010 the FFmpeg developers
  built on Oct  5 2010 22:36:53 with gcc 4.4.5
  configuration: --extra-version=4:0.6-2ubuntu6 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.11. 0 /  0.11. 0
  libpostproc   51. 2. 0 / 51. 2. 0
[mp3 @ 0x7ae420]max_analyze_duration reached
[mp3 @ 0x7ae420]Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'http://physics.ujep.cz/~mmaly/mp3/Mozart/Mass_in_C_Minor_New_by_Levin/sbory_vyssi_kvalita/01_Kyrie.mp3':
  Metadata:
    TLEN            : 431046
    TIT2            : Kyrie
    TRCK            : 1
    TPE1            : Mozart
    TCON            : Classical
    TALB            : Mass in C Minor New by Levin
  Duration: 00:07:11.18, start: 0.000000, bitrate: 128 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, 2 channels, s16, 128 kb/s
At least one output file must be specified



回答2:


Depends on if you want to read ID3v1 or ID3v2. ID3v1 is always at the end of the file, so if you are interested in reading that no go. ID3v2 usually occurs at the start of the file, but there's no guarantee for that.

So if you don't want to accidentally miss any tags, you have to read the whole file. The ID3v1 problem can be solved by reading from the end of the file, but that doesn't help with ID3v2.



来源:https://stackoverflow.com/questions/5359279/read-id3-tags-without-downloading-the-whole-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!