1

I'm using youtube-dl to download from youtube. I would like to download the files as mp3. Doing some research I found that there's a function for this: --audio-format mp3. However when I use this it still downloads the files as m4a or webm. The function I'm using is

youtube-dl --extract-audio --audio-format mp3 <link>

Now it gives a hint to install ffmpeg or avconv, but after doing pip install ffmpeg it still doesn't work. How do I fix this?

Thanks in advance!

Jellyfish
  • 67
  • 9
  • You need to download the [`ffmpeg`](https://ffmpeg.org/download.html#build-windows) or `avconv` programs, install them or put the binaries somewhere on your system, and set your `PATH` so that `youtube-dl` can find the binaries. – wkl Aug 17 '22 at 13:52

2 Answers2

0

You might need to install ffmpeg through apt-get instead of pip. Not sure which distro you are on.

Oempff
  • 21
  • 4
0

I wrote a python script to solve this because I spent way to long trying to get to work.

https://github.com/hackerman-jpeg/YouTube_Downloader

I use FFMPEG to convert:

info = yt_dlp.YoutubeDL().extract_info(url, download=False)
input_file = f'downloads/{info["title"]}-{info["id"]}.{info["ext"]}'
output_file = f'downloads/{info["title"].split(" - ")[0]} - {info["title"].split(" - ")[1]}.mp3'
subprocess.run(["ffmpeg", "-i", input_file, "-ab", "320k", output_file])

You can go see the whole script for details. I added a handy user prompt for URLs.

Ftagliacarne
  • 675
  • 8
  • 16