Download ONLY audio from a youtube video

2019-01-21 09:50发布

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!

3条回答
我只想做你的唯一
2楼-- · 2019-01-21 10:14

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.

查看更多
在下西门庆
3楼-- · 2019-01-21 10:28

Well, Now its possible to download only audio of youtube video and for that i use this youtube 2 mp3 api

It works very well for me. all you need to put youtube id and that's it.

查看更多
做个烂人
4楼-- · 2019-01-21 10:29

After a lot of research I found out this is not possible and developer 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

查看更多
登录 后发表回答