0%

Audio Extraction

Usefulness

  • convert video like mp4 or flv to audio like flac

Environment

Install tools

  1. ffmpeg

    • use winget or download ffmpeg from the official website

      1
      winget install --id=Gyan.FFmpeg  -e
    • add the ffmpeg directory to the environment variable

    • The winget installation directory is generally in

      1
      C:\Users\[user name]\AppData\Local\Microsoft\WinGet\Packages\Gyan.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-6.0-full_build\bin
  2. yt-dlp

    • use winget or download yt-dlp from the github releases

      1
      winget install yt-dlp
    • add the ffmpeg directory to the environment variable

Basic steps

  1. open a terminal and download the video

    1
    yt-dlp [video link]
  2. convert video to flac with ffmpeg

    1
    ffmpeg -i [video] -acodec flac [audio name].flac

Batch conversion with bat script

  1. create a file with the suffix .bat and fill in the following content

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    @echo off
    set a=1
    setlocal EnableDelayedExpansion
    FOR /F "delims=\" %%i IN ('dir /b *.flv') DO (
    ren "%%i" "!a!.tmp"
    ffmpeg -i "!a!.tmp" -acodec flac "!a!.flac"
    ren "!a!.flac" "%%i.flac"
    ren "!a!.tmp" "%%i"
    : else ( echo "ha" >> tmp.txt )
    set /A a+=1
    echo !a!
    )
    FOR /F "delims=\" %%i IN ('dir /b *.mp4') DO (
    ren "%%i" "!a!.tmp"
    ffmpeg -i "!a!.tmp" -acodec flac "!a!.flac"
    ren "!a!.flac" "%%i.flac"
    ren "!a!.tmp" "%%i"
    : else ( echo "ha" >> tmp.txt )
    set /A a+=1
    echo !a!
    )
  2. just double-click the bat script to convert flv and mp4 in the current directory to flac

Final

  • Sometimes the beginning and end of the audio are redundant, so we can use ffmpeg to cut

    1
    ffmpeg -i [original audio name].flac -ss [starting time] -t [duration] [output audio name].flac