Python 如何在 Windows 上使用 youtube-dl 提取音频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14185867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to extract audio with youtube-dl on Windows
提问by FlyingNimbus
I want to extract audio from a video downloaded with youtube-dl on Windows. I got youtube-dl working, but am unable to extract the audio. This problem is caused due to not having the correct audio codes installed.
我想从在 Windows 上使用 youtube-dl 下载的视频中提取音频。我让 youtube-dl 正常工作,但无法提取音频。这个问题是由于没有安装正确的音频代码引起的。
When I try to extract audio it tells me the following:
当我尝试提取音频时,它告诉我以下内容:
WARNING: unable to obtain file audio codes with ffprobe
The youtube-dl manual says:
youtube-dl 手册说:
-x -extract-audio convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)
How do I install ffprobe or ffmpeg? Do I install this on Windows, or do I install this as a Python extension?
如何安装 ffprobe 或 ffmpeg?我是在 Windows 上安装它,还是将它安装为 Python 扩展?
My OS is Windows 7.
我的操作系统是 Windows 7。
采纳答案by Fredrick Brennan
ffmpegis not a Python module. Take a look at the code of youtube-dlin the FFmpegExtractAudioPPclass.
ffmpeg不是 Python 模块。看看的代码youtube-dl的FFmpegExtractAudioPP类。
It uses this call to figure out if the executable exists or not. It checks in your current path:
它使用此调用来确定可执行文件是否存在。它检查您当前的路径:
subprocess.Popen([exe, '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
You'll need to download the Windows builds of ffmpegand put them in your current path, probably making sure that they do not have .exeat the end of their names.
您需要下载Windows 版本ffmpeg并将它们放在当前路径中,可能要确保它们.exe的名称末尾没有。
回答by Robert Rowntree
You can use the RTSP stream URL for the format type 1 feed listed in the common Youtube API. Call it for the feed info.
您可以将 RTSP 流 URL 用于常见 Youtube API 中列出的格式类型 1 提要。调用它获取提要信息。
Get the YouTube feed which contains a number of URLs.
获取包含多个 URL 的 YouTube 供稿。
Get the 'format type 1' URL.
获取“格式类型 1” URL。
Call that with an RTSP client and you can store the audio directly.
使用 RTSP 客户端调用它,您可以直接存储音频。
See "YouTube feed" in "is Android single task or multitasking and multithreading? " for how to get type 1 URL.
有关如何获取类型 1 URL 的信息,请参阅“ Android 是单任务还是多任务和多线程? ”中的“YouTube 提要” 。
See http://snipplr.com/view/63341/youtube-rtsp-cli-request--audio-track-only-p2/for how to get audio once you have the URL.
请参阅http://snipplr.com/view/63341/youtube-rtsp-cli-request--audio-track-only-p2/了解如何在获得 URL 后获取音频。
There's more information at: "youtube rtsp CLI request - AUDIO TRACK only".
回答by Sunil Kumar
A quick fix for Windows users:
Windows 用户的快速修复:
- Download the ffmpeg package from http://ffmpeg.zeranoe.com/builds/, unzip it, copy ALL the contents of the Bin directory to the directory where youtube-dl.exe is located.
Using DOS navigate to the directory where youtube-dl is located and run using the command:
youtube-dl --extract-audio --audio-format mp3
- 从http://ffmpeg.zeranoe.com/builds/下载 ffmpeg 包,解压,将 Bin 目录下的所有内容复制到 youtube-dl.exe 所在目录。
使用 DOS 导航到 youtube-dl 所在的目录并使用以下命令运行:
youtube-dl --extract-audio --audio-format mp3

