A Powershell ffmpeg Snippet

This is a short snippet to convert a bunch of mp4 movie files to webp format using ffmpeg.

A little verbose perhaps, but I find it easy to remember and recreate, and it makes sense when you read it.

Built in progress bar, and no worries about quoting or escaping stuff! Take that !#bash

Have something else that won't be finished in seconds? Replace the *mp4 input, and the ffmpeg line with whatever program/process you need.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# using the reasonable defaults, size down to 640x480, one pass, with a progress bar
# for a whole folder of mp4s.  Reduction in file size is remarkable.

$count=0
$fred=get-childitem *mp4
foreach ($entry in $fred) {
    $count++
    $in=$entry.name
    $out=$entry.basename+".webm"
    $percentage = ($count/$fred.length*100)
    $activity = "Converting {0} of {1} ..." -f $count, $fred.length
    write-progress -Activity $activity -Status $in -PercentComplete $percentage
    ffmpeg -hide_banner -loglevel error  -i $in -vf scale=640:-1 $out
}

Please note - ffmpeg options aren't a rabbit hole, they're a Marianas Trench of infinite darkness and pressure. Enter at your own risk... Me, I'm happy in my floaty on the surface.

links

social