仅从 youtube 视频下载音频 [英] Download ONLY audio from a youtube video

查看:39
本文介绍了仅从 youtube 视频下载音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有上百万种方法可以从 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

不幸的是,这些命令中没有一个似乎使用较少的带宽.他们都下载了整个视频.现在你有了视频,你能确认是否真的有一个命令可以只下载音频流并降低带宽使用率吗?谢谢!

经过大量研究,我发现这是不可能的,并开发了一种替代方法:

  1. 下载 mp4 标头
  2. 解析头部并获取音频字节的位置
  3. 下载带有 http 范围请求和偏移量的音频字节
  4. 组合音频字节并将它们包装在一个简单的 ADTS 容器中以生成一个正在播放的 m4a 文件

那样只使用音频字节的带宽.如果您找到更好的方法,请告诉我.

有关示例 Android APP 和实施检查:

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

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!

解决方案

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

这篇关于仅从 youtube 视频下载音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆