17

I know that there are a million ways to download a video from youtube and then convert it to audio or do further processing on it. But recently I was surprised to see an app called YoutubeToMp3 on mac actually showing "Skipping X mb of video" and supposedly only downloading the audio from the video, without the need to use bandwith to download the entire video and then convert it. I was wondering if this is actually correct and possible at all because I cant find any way to do that. Do you have any ideas ?

EDIT: After some tests here is some additional information on the topic. The video which I tried to get the audio from is just a sample mp4 file from the internet:

http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/MediaCoder/MediaCoder_test6_1m9s_XVID_VBR_306kbps_320x240_25fps_MPEG1Layer3_CBR_320kbps_Stereo_44100Hz.mp4

I tried

ffmpeg -i "input" out.mp3

ffmpeg -i "input" -vn out.mp3

ffmpeg -i “input” -vn -ac 2 -ar 44100 -ab 320k -f mp3 output.mp3

ffmpeg -i “input” -vn -acodec copy output.mp3

Unfortunately non of these commands seems to be using less bandwith. They all download the entire video. Now that you have the video can you confirm if there is actually a command that downloads only the audio stream from it and lowers the bandwith usage? Thanks!

Feras
  • 2,114
  • 3
  • 20
  • 42
  • The server probably allows you to seek when downloading. I.e. if the download link is seekable, then why not. – sashoalm Mar 06 '13 at 07:24
  • Does this YoutubeToMp3 app use FFmpeg as the backend? Try capturing and seeing what command line arguments it's passing to FFmpeg. – sashoalm Mar 06 '13 at 08:31
  • If you open an YouTube URL with JDownloader, it will propose you several downloads, one FLV file for each resolution, the picture, and the MP3 ;) – Andrea Ligios Mar 06 '13 at 12:50

2 Answers2

24

After a lot of research I found out that this is not possible and developed an alternative approach:

  1. Download the mp4 header
  2. Parse the header and get the locations of the audio bytes
  3. Download the audio bytes with http range requests and offsets
  4. Assemble the audio bytes and wrap them in a simple ADTS container to produce a playing m4a file

That way only bandwidth for the audio bytes is used. If you find a better approach of doing it please let me know.

For a sample Android APP and implementation check out:

https://github.com/feribg/audiogetter/blob/master/audiogetter/src/main/java/com/github/feribg/audiogetter/tasks/download/VideoTask.java

Vigrant
  • 898
  • 1
  • 17
  • 27
Feras
  • 2,114
  • 3
  • 20
  • 42
3

FFmpeg is capable of accepting an URL as input. If the URL is seekable, then FFmpeg could theoretically skip all the video frames, and thus it would need to download only the data for the audio stream.

Try using

ffmpeg -i http://myvideo.avi out.mp3

and see if it takes less bandwidth.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • Starts working and freezes at: libavutil 51. 73.101 / 51. 73.101 libavcodec 54. 59.100 / 54. 59.100 libavformat 54. 29.104 / 54. 29.104 libavdevice 54. 2.101 / 54. 2.101 libavfilter 3. 17.100 / 3. 17.100 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 15.100 / 0. 15.100 libpostproc 52. 0.100 / 52. 0.100 – Feras Mar 06 '13 at 08:14
  • Well that is the way to do it using FFmpeg at least. You asked how do you convert only the audio. That's how. It's supposed to be working, but there could be bugs, of course. Try filing a bug in their mailing list or debugging it yourself. – sashoalm Mar 06 '13 at 08:18
  • This will never work with YouTube. FFmpeg expects an actual file as input, not a YouTube URL. That's not what it's meant to parse. If the link points to a valid video stream or file, then it should work, but YouTube embeds the video as Flash, so there's no way for FFmpeg to parse that unless they added explicit support for YouTube. Tools such as `youtube-dl` do a much better job at this. – slhck Mar 24 '13 at 20:50
  • 1
    He'll need to parse the HTML to get to the actual content URL of course, but there are plenty of free and open-source tools that does this - [youtube-dl.py](http://rg3.github.com/youtube-dl/) for example. He could rewrite them to just print out the content URL instead of downloading it. Besides, this was just tangential to his question, he was asking if it's possible to save bandwidth by downloading only the audiostream of a big video file, he gave YouTubeToMp3 only as an example of a tool that does it. – sashoalm Mar 25 '13 at 08:02