Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download ONLY audio from a youtube video

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!

like image 437
Feras Avatar asked Mar 06 '13 07:03

Feras


People also ask

How do I download an audio from YouTube?

Step 1: Go to the 320YouTube website. Copy and paste the Youtube URL for the video or song you want to convert to Mp3 in the box. Hit the 'Convert' button. Step 2: It will show you the video you want to download on the left-hand side, click on the 'Download Mp3' button to convert your YouTube video to an audio file.


2 Answers

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

like image 117
Feras Avatar answered Sep 20 '22 05:09

Feras


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.

like image 37
sashoalm Avatar answered Sep 20 '22 05:09

sashoalm