I’m writing this one quickly as it’s been a while and I forgot about all the formatting and nice organization that I would otherwise love to keep putting into these. It’d due for a refresh.
In any case, today I spent some time working along ChatGPT my mentor to come up with a script that can quickly crop square videos into the classic 16:9 and 9:16 aspect ratios.
The script points to your ffmpeg path, and as always I just dropped the bat file into the “sendTo” shell folder. If this sounds like nonsense, it’s because I purposedly write obtusely to try to look cooler.
1. How do I install the thing?
It take approx 1-3 minutes so buckle up. There are two elements to this tool: ffmpeg and the batch script.
a. ffmpeg
Most likely you already have ffmpeg installed on your computer. But if you don’t you’re going to want to get it clicking here (windows):
After downloading, extract the folder and rename it to just “ffmpeg”. Then, place it on your C:/Program Files/ folder, that it ends like this:
If there is already an ffmpeg folder there, it means you already have it installed and can move to the next step.
b. The script
You can download the script from here, or make it yourself.
I don’t know if windows will have issues with downloading “.bat” files from the internet without freaking out, so if the download doesn’t work you can make it yourself:
Create a .txt file anywhere. Open it to edit, and paste the following code:
@echo off
setlocal enabledelayedexpansion
set "ffmpeg_path=C:\Program Files\ffmpeg\bin\ffmpeg.exe"
set "ffprobe_path=C:\Program Files\ffmpeg\bin\ffprobe.exe"
set "input_file=%~1"
if not exist "%input_file%" (
echo Input file does not exist.
exit /b
)
for %%I in ("%input_file%") do (
set "filename=%%~nI"
set "extension=%%~xI"
)
set "output_directory=%filename%_SOCIAL"
if not exist "%output_directory%" mkdir "%output_directory%"
set "output_file_16x9=%output_directory%\!filename!_16x9!extension!"
set "output_file_9x16=%output_directory%\!filename!_9x16!extension!"
for /F "usebackq tokens=1,2 delims=: " %%A in (`"%ffprobe_path%" -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "%input_file%"`) do (
set "input_width=%%A"
set "input_height=%%B"
)
set /A output_width_16x9=input_width
set /A output_height_16x9=output_width_16x9*9/16
set /A output_width_9x16=input_height*9/16
set /A output_height_9x16=input_height
if !input_width! gtr !input_height! (
set "max_resolution=!input_width!"
) else (
set "max_resolution=!input_height!"
)
if !output_width_16x9! gtr !max_resolution! set "output_width_16x9=!max_resolution!"
if !output_height_16x9! gtr !max_resolution! set "output_height_16x9=!max_resolution!"
if !output_width_9x16! gtr !max_resolution! set "output_width_9x16=!max_resolution!"
if !output_height_9x16! gtr !max_resolution! set "output_height_9x16=!max_resolution!"
"%ffmpeg_path%" -i "%input_file%" -vf "crop=w=iw:h=trunc(iw*9/16),scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -crf 23 -c:a copy "%output_file_16x9%"
"%ffmpeg_path%" -i "%input_file%" -vf "crop=w=trunc(ih*9/16):h=ih,scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -crf 23 -c:a copy "%output_file_9x16%"
endlocal
After that, save the file and rename it to “Crop to Socials.bat”. Make sure that the extension changes to .bat.
c. Creating the shortcut
You can put the “.bat” file inside:
Alternatively, you can press Windows Key + R, and type:
Then press OK. This will take you to the same folder. You can rename the file to whatever you want. And now, you should be able to easily right click on any video file, Send To → and watch the magic happen!