1. Intro
Here we are again! This time I bring you a little script that will let us add colored borders to any image or video, even multiple ones at a time. We do this with the help of ffmpeg. If you don’t know what ffmpeg is, here’s a quote from its site:
“FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created”
What this basically means is that it’s a cool tool that lets you mess around with video and images. A lot of the software and programs that you use or have used in the past probably rely on ffmpeg for some tasks. For our little script to work. If you think you’ve installed ffmpeg in the past -or some app might have done that for you- feel free to skip to the script part directly.
If you don’t have ffmpeg installed, when running the script you will see this message:
If you’re not sure or you know you don’t have ffmpeg installed, I made a little guide for you and it will take about two minutes really:
a) Installing ffmpeg
This essentially consists on downloading a folder, putting it somewhere in our PC and then adding an Environment Variable. And environment variable is a way to tell everything in our PC “Hey, this is where ffmpeg is!”.
Firstly, Download ffmpeg from here:
That’s it. Ffmpeg is installed and set up as an environment variable. Now we can get to the fun part!
2. Creating the script
Now that we have ffmpeg, we just need to create a basic batch script that tells ffmpeg to add a border. We will use variables and a prompt for the user (us) to select the thickness and color. To do this, we make a .txt file and we type the code:
@ECHO OFF
set /p winput=Thickness (px):
set /a width= %winput%*2
set /a xz= %width%/2
set /a yz= %width%/2
set /p "colorpick=Pick a color (HEX) value or press ENTER for White (#FFFFFF): "
if not defined colorpick (
set "colorpick=#FFFFFF"
)
echo %colorpick%
for %%i in (%*) do if not exist "%%~i.png" (
ffmpeg -i "%%~i" -filter_complex "[0]pad = w=%width%+iw : h=%width%+ih: x=%xz% : y=%yz% : color=%colorpick%" "%%~ni_border_%winput%px%~x1"
)
Then we change the .txt extensio to “.bat” and our script is ready to run. You can drag any images and videos onto it.