1

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.

Wisco crew
  • 1,337
  • 1
  • 17
  • 25
  • Here is a similar question: http://stackoverflow.com/questions/8543214/is-it-possible-to-download-just-part-of-a-zip-archive-e-g-one-file You can download a part of the file but I don't no if you be able to use the mp3 file after that. – FrediWeber Mar 03 '12 at 16:54
  • Downloading over what? HTTP? – Brad Mar 03 '12 at 16:54

1 Answers1

3

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.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Would it be possible if I don't need _exactly_ 30 seconds? Say anywhere from 20-40 is fine. – Wisco crew Mar 03 '12 at 17:02
  • @Wiscocrew, Not really, unless you wanted anywhere from 5:00 to :05. You can experiment with grabbing the last x number of bytes from the file. First, do a HEAD request to figure out how long the file is, and then pick the last 700KB or so. Again though, this is so variable that you could be getting anything. – Brad Mar 03 '12 at 17:10