FFmpeg Scripts

    No Comments

    One of my duties at Church is recording the service and posting that online later in the week. This means I spend a fair amount of time each week working with video and audio recordings. One of my favorite tools that can handle both is FFmpeg. As a command-line utility, FFmpeg is a no-fuss utility that just works as you tell it. However, this also means you could spend a lot of time making sure you type exactly what you want.

    To assist with consistency, I’ve started using a series of Windows batch files that will make sure I’m using the same settings each time. This has become my favorite way to convert audio and video files.

    • Extract audio as wav.bat: This will extract the audio from any input file and convert it to .wav
    • Scale to 720p 29_97.bat: Most of the video files I work with are 1080p, 29.97 fps with high bitrates on audio and video. This script will change that to 720p with lower bitrates.
    • Extract AAC.bat: Like the .wav extract, this will extract the AAC. I use this to export the audio from videos I’ve compiled, so the script expects AAC format on the audio track of the video.
    • RunAllThroughBat.bat: On this one I pass in one of the other .bat files. So if I run this with “Extract AAC.bat”, it will find all the .mp4 videos in the current folder and extract the audio to .aac files.
    • Convert AVI to MP4.bat: Another that has a slightly unclear name. The source doesn’t have to be AVI, but that’s what I was using the script for at the time. I had recordings of several episodes from an old TV show. These recordings were made over a while and from different TV stations, so they lacked consistency. This converts them to MP4, normalizes the audio, and sets the movflag to fast start to make streaming better on Plex/Kodi. The script converts the file and moves it to my NAS where Plex picks it up.

    Extract audio as wav.bat

    set inFile=%1
    set outFile=%1.wav

    C:\ffmpeg\bin\ffmpeg.exe -i %inFile% -ac 1 -threads 4 %outFile%

    Scale to 720p 29_97.bat

    set inFile=%1
    set outFile=%1_720.mp4
    C:\ffmpeg\bin\ffmpeg.exe -i %inFile% -b:v 1500k -b:a 96k -vf "fps=29.97, scale=-1:720" -threads 4 %outFile%

    Extract AAC.bat

    set inFile=%1
    set outFile=%~n1.aac
    C:\ffmpeg\bin\ffmpeg.exe -i %inFile% -vn -codec:a copy "%outFile%"

    RunAllThroughBat.bat

    set fileType=mp4
    set runBat=%1
    for %%j in (*.%fileType%) do (
    %runBat% %%j
    )

    Convert AVI to MP4.bat

    set inFile=%1
    set outFile=W:\Plex\TV\Show\SeasonX\%~n1.mp4
    C:\ffmpeg\bin\ffmpeg.exe -n -i %inFile% -c:v libx264 -codec:a libmp3lame -movflags faststart -filter:a loudnorm "%outFile%"
    Categories: FFmpeg, Scripts