How to extract audio with youtube-dl on Windows
Asked Answered
I

5

8

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.

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:

-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?

My OS is Windows 7.

Isoelectronic answered 6/1, 2013 at 19:29 Comment(0)
K
13

ffmpeg is not a Python module. Take a look at the code of youtube-dl in the FFmpegExtractAudioPP class.

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 ffmpeg and put them in your current path, probably making sure that they do not have .exe at the end of their names.

Kommunarsk answered 6/1, 2013 at 19:38 Comment(3)
Thanks for the response, would you be so kind to help me out a little more detailed, it would save me a lot of time. Which files do i need to download exactly and what do I do with them? Do I need to remove the exe? Do I need to change the python code? I have never written python before so i wouldn't know how :SIsoelectronic
@user1160265 I think your question is better suited to SuperUser if it isn't a programming question.Kommunarsk
Thanks for this answer; it really helped me. I don't think having .exe as the extension of the ffmpeg binaries matters, though. I just extracted the ffmpeg build to C: and added its bin directory to my PATH, and ytdl worked fine. (I'd edit your answer, but I'm not confident enough to generalize to everybody)Nurserymaid
A
7

A quick fix for Windows users:

  1. 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.
  2. Using DOS navigate to the directory where youtube-dl is located and run using the command:

    youtube-dl --extract-audio --audio-format mp3
    
Acquisition answered 12/3, 2017 at 7:45 Comment(2)
Thanks! I've searched for this for quite a while. I've searched around the internet and some people say to put it inside a 'bin' folder in the installation folder or FFmpeg/bin or use the --FFmpeg-location. Nothing helped besides bluntly putting the executables in the youtubedl folder.Screed
That site no longer existsAngelenaangeleno
R
5

EDIT

Future users may want to download the latest build from ffmpeg.org


My rep doesn't allow me to add a comment so I will put in here.

As per Sep 18, 2020 http://ffmpeg.zeranoe.com/builds/ is closed, but still accessible via Web Archive. The complete downloads are still available from here:

http://web.archive.org/web/20200918193047/https://ffmpeg.zeranoe.com/builds/

I have made the following files/versions available for Windows users from my Google Drive but please don't take these as granted, and scan for malware or viruses as always:

ffmpeg-4.2.2-win32-static.zip
ffmpeg-4.2.2-win64-static.zip
ffmpeg-4.2.3-win32-static.zip
ffmpeg-4.2.3-win64-static.zip
ffmpeg-4.3-win32-static.zip
ffmpeg-4.3-win64-static.zip
ffmpeg-4.3.1-win32-static.zip
ffmpeg-4.3.1-win64-static.zip
    

https://drive.google.com/drive/folders/1oj3VndOC-bGhfpNcHW3otIR--V2wxdG-?usp=sharing

Once downloaded, I extracted the latest build (4.3.1) on Windows 10 and copied all the .exe (ffmpeg, ffplay, ffprobe) to the same directory as youtube-dl, and then run:

youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=...
Rightwards answered 31/12, 2020 at 4:39 Comment(0)
M
0

You can easily get win-ffmpeg using chocolatey

and if you still can’t get youtube-dl and ffmpeg to work together,

maybe you can do it in two steps:

  1. Get mp4 or avi : youtube-dl url

  2. Extract audio

    ffmpeg -i input.mp4 -vn -codec copy out.mp3

Machutte answered 29/1, 2021 at 10:11 Comment(0)
C
0

I use packages available on conda-forge to accomplish this on Windows. The yt-dlp script should be in your %PATH% after installation in a conda environment. Note: I tested this with Git Bash, not Windows Terminal/Powershell

(yt-dlp) $ conda install ffmpeg yt-dlp
(yt-dlp) $ yt-dlp --version
(yt-dlp) $ ffmpeg --version
(yt-dlp) $ yt-dlp --extract-audio --audio-format wav https://www.youtube.com/watch?v=BaW_jenozKc

You can also do this with Python code. Most of the Python code below was taken from yt-dlp documentation.

import yt_dlp


URLS = ['https://www.youtube.com/watch?v=BaW_jenozKc']


# https://github.com/yt-dlp/yt-dlp#extract-audio
ydl_opts = {
    'format': 'm4a/bestaudio/best',
    # See help(yt_dlp.postprocessor) for a list of available
    # Postprocessors and their arguments
    'postprocessors': [{  # Extract audio using ffmpeg
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'wav'
    }]
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    error_code = ydl.download(URLS)
Creationism answered 25/9, 2023 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.