Batch script to convert, youtube-dl webm file to mp3 with ffmpeg

27,274

Solution 1

You can convert through this script:

for FILE in *.webm; do
    echo -e "Processing video '\e[32m$FILE\e[0m'";
    ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
done;

Save it into a .sh file and execute it. It will automatically convert all the .webm into .mp3

Solution 2

webm either uses vorbis or opus audio codec, both are far superior to mp3 in quality. aac audio is available on youtube, which is somewhere between opus and vorbis in quality and is heavily supported by media players and gadgets. quality wise, re-encoding lossy audio to another lossy audio is not recommended, especially if one of those autio formats is mp3.

i'd grab that aac if i were you.

as per this answer:

youtube-dl -f bestaudio[ext=m4a] --embed-thumbnail --add-metadata <Video-URL>
Share:
27,274
SneakyShrike
Author by

SneakyShrike

Updated on July 09, 2022

Comments

  • SneakyShrike
    SneakyShrike almost 2 years

    I'm using youtube-dl to extract the best possible audio quality from youtube videos. However the best quality audio usually turns out to be the webm format, which isn't useful. I would like to write a batch script that converts the webm file to an mp3 with ffmpeg. I've already tried using this guide on reddit to do it, but it doesn't seem to work. It appears to create an empty mp3 file that displays an error when i try to play it and the meta data is also completly blank.

    Here is the batch script:

    for %%a in ("Downloaded\*.*") do %CD%\ffmpeg\bin\ffmpeg.exe -i "%%a" -vn -ar 44100 -ac 2 -ab 192k -f mp3 "Converted\%%~na.mp3" pause
    

    I'll also give an explanation of how the whole thing should work.

    The idea is, is that you use youtube-dl to extract the best possible audio, then put that file into the Downloaded folder (see pic below) and then you run the mp3 script (which uses commands from ffmpeg) to convert the webm file in the Downloaded folder to a mp3 file, and place it in the Converted folder. The mp3 script is the code above. But it doesn't seem to work properly.

    I'm not very familiar with batch scripting, nor with ffmpeg so any help would be appreicated.

    Here is the picture to complement the explanation part.

    enter image description here