Download last 30 seconds of an mp3

喜夏-厌秋 提交于 2019-12-24 16:27:23

问题


Is it possible to download only the last 30 seconds of an mp3? Or is it necessary to download the whole thing and crop it after the fact? I would be downloading via http, i.e. I have the URL of the file but that's it.


回答1:


No, it is not possible... at least not without knowing some more information first.

The real problem here is determining at what byte offset the last 30 seconds is. This is a product of knowing:

  • Sample Rate
  • Bit Depth (per sample)
  • # of Channels
  • CBR or VBR
  • Bit Rate

Even then, you're not going to get that with a VBR MP3 file, and even with CBR, who knows how big the ID3 and other crap at the beginning of the file is. Even if you know all of that, there is still some variability, as you have the problem of the bit reservoir.

The only way to know would be to download the whole file and use a tool such as FFMPEG to find out the right offset. Then if you want to play it, you'll want to add the appropriate headers, and make sure you are trimming on an eligible frame, or fix the bit reservoir yourself.

Now, if this could all be figured out server-side ahead of time, then yes, you could request the offset from the server, and then download from there. As for how to download it, your question is very incomplete and didn't mention what protocol you were using, so I cannot help you there.



来源:https://stackoverflow.com/questions/9547830/download-last-30-seconds-of-an-mp3

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