仅从 youtube 视频下载音频 [英] Download ONLY audio from a youtube video
问题描述
我知道有上百万种方法可以从 youtube 下载视频,然后将其转换为音频或对其进行进一步处理.但最近我惊讶地看到 Mac 上一个名为 YoutubeToMp3 的应用程序实际上显示跳过 X mb 的视频"并且据说只从视频中下载音频,而无需使用带宽下载整个视频然后进行转换.我想知道这是否真的正确并且可能,因为我找不到任何方法来做到这一点.你有什么想法吗?
经过一些测试,这里是有关该主题的一些附加信息.我试图从中获取音频的视频只是来自互联网的示例 mp4 文件:
ffmpeg -i "input" -vn out.mp3
ffmpeg -i 输入" -vn -ac 2 -ar 44100 -ab 320k -f mp3 output.mp3
ffmpeg -i input" -vn -acodec copy output.mp3
不幸的是,这些命令中没有一个似乎使用较少的带宽.他们都下载了整个视频.现在你有了视频,你能确认是否真的有一个命令可以只下载音频流并降低带宽使用率吗?谢谢!
经过大量研究,我发现这是不可能的,并开发了一种替代方法:
- 下载 mp4 标头
- 解析头部并获取音频字节的位置
- 下载带有 http 范围请求和偏移量的音频字节
- 组合音频字节并将它们包装在一个简单的 ADTS 容器中以生成一个正在播放的 m4a 文件
那样只使用音频字节的带宽.如果您找到更好的方法,请告诉我.
有关示例 Android APP 和实施检查:
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 that this is not possible and developed 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 视频下载音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!