问题描述
我知道有一百万种方式可以从YouTube下载视频,然后将其转换为音频或进行其他处理。但最近,我惊讶的发现一个名为YoutubeToMp3的应用程序在Mac上实际显示Skipping X mb of video,据说只能从视频中下载音频,而无需使用bandwith下载整个视频,然后转换。我想知道这是否真的是正确的,可能的,因为我无法找到任何办法。你有什么想法吗?
编辑:
经过一些测试后,有一些关于该主题的附加信息。我试图获得音频的视频只是一个来自互联网的mp4文件:
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:
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!
After a lot of research I found out this is not possible and developer an alternative approach:
- Download the mp4 header
- Parse the header and get the locations of the audio bytes
- Download the audio bytes with http range requests and offsets
- 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:
这篇关于从YouTube视频下载只有音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!