4

I understand that I can make a range request to download a specific time range for a streaming web video.

I'm wondering now if it is possible to request only the MP3 or AAC audio stream from a video, so that on my server, I only download audio.

From what I've heard this is possible, but I've yet to find any legitimate solution or method for doing this on the web, so I don't really know where to start.

pepper
  • 2,097
  • 5
  • 23
  • 29
  • I think you probably heard about [ffmpeg](http://www.ffmpeg.org) or similar tools, that can do this. Examples [here](http://peppoj.net/2010/09/how-to-extract-audio-from-video-using-ffmpeg/) and [here](http://stackoverflow.com/questions/9913032/ffmpeg-to-extract-audio-from-video). But, it must be done on the server in advance of the client request to download the file, perhaps it's possible to do it in near real time. – Sunil D. Mar 08 '13 at 16:43
  • Thanks for this...the point though is to ONLY DOWNLOAD THE AUDIO, and therefore downloading less data at a potentially faster rate. – pepper Mar 08 '13 at 18:09
  • 2
    You can't do that. How do you tell a client download these bits but not those? My point is that you need to do something on the server so that the server only provides the audio bits. I think the only option is to use something like ffmpeg :) – Sunil D. Mar 08 '13 at 18:11
  • @SunilD., You can use range requests. http://stackoverflow.com/a/8507991/362536 – Brad Mar 09 '13 at 15:02

1 Answers1

6

Assuming you are talking about streams over HTTP, this isn't really feasible. I really wouldn't even recommend trying it, unless you have a very specific need and a lot of time on your hands.

Is it possible? Maybe. First off, you have to have an HTTP server that supports range requests. If it does, then you have to know something about the container format. For that, you have to start downloading the file and figure that out.

Most containers interleave streams together. That is, you will have a chunk of bytes for the video, a chunk of bytes for the audio, and chunks for any other streams present. For demonstration purposes, suppose a video only has an audio stream and video stream, and each chunk contains 1 second worth of content. The interleaving looks like this:

HEADERS A V A V A V A V A V A V A V ...

HEADERS is everything the container has for setting up the stream. A is an audio stream chunk, and V is a video stream chunk.

If you want to download just one stream, you have to be able to parse that container format yourself, download the container headers and any other data you need for the container, and then make range requests for all of the chunks of the particular stream you want. Depending on the interleaving, in the end, this may not be very efficient at all!

As you are downloading your data, you then need to write it back to a file you can actually use, which means you will likely need to write some custom code for doing so, or trick FFMPEG into writing it for you.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Wow, very cool, indeed. At least I can take heart in knowing that the possible solution is not so feasible :) – Sunil D. Mar 09 '13 at 15:58