3

I am trying to extract an audio from a YouTube Video as an .wav file. However, the script that I am running keeps giving me .webm files. The code I am using is the following:

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'wav',
        'preferredquality': '192'
    }],
    'postprocessor_args': [
        '-ar', '16000'
    ],
    'prefer_ffmpeg': True,
    'keepvideo': True
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=2Xq7iJKzhR4'])

Is there a way to change the output and keep the highest possible audio quality?

I tried setting prefer_ffmpeg': True to False & keepvideo': True to False but that did not change anything.

I would appreciate suggestions and please keep in mind that I never used Python before.

  • My understanding is that all videos uploaded to youtube are converted to WebM, so you may not be able to get it in any other format. Is there any reason why you can't download as a .wav and then run a script to convert it manually (like this https://stackoverflow.com/questions/6954845/how-to-create-a-webm-video-file)? – Blake F. Sep 25 '22 at 21:35

0 Answers0