Skip to content

Instantly share code, notes, and snippets.

@JustOurStyle
Last active January 20, 2023 05:42
Show Gist options
  • Save JustOurStyle/999d20609c78587453d5e2f72e8becd2 to your computer and use it in GitHub Desktop.
Save JustOurStyle/999d20609c78587453d5e2f72e8becd2 to your computer and use it in GitHub Desktop.

Windows Batch File to Split MidJourney 2x2 Grids Using ffmpeg

The following simple batch file will loop through your 2x2 grids (in either .png or .webp formats) and split them into separate PNG file using the ffmpeg utility.

This batch file requires ffmpeg to be installed, and in your system PATH (or in the same directory as the batch file).

It works for any aspect ratio grid.

The 2x2 grids should be in a _RAW_GRIDS directory. The split grids will be copied to _SPLIT_GRIDS as -01 -02 -03 -04 PNG files. (See below for example setup)

(If you only have PNG grids you can get rid of the webp loop, but some old grids are in webp format.)

By default it won't overwrite any existing split grids if they already exist (the -n parameter to ffmpeg does this).

Save the following code into a file split-grids.bat

for %%f in ("_RAW_GRIDS/*.webp") do (
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:0:0" "_SPLIT_GRIDS\%%~nf-01.png"
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:iw/2:0" "_SPLIT_GRIDS\%%~nf-02.png"
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:0:ih/2" "_SPLIT_GRIDS\%%~nf-03.png"
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:iw/2:ih/2" "_SPLIT_GRIDS\%%~nf-04.png"
)
for %%f in ("_RAW_GRIDS/*.png") do (
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:0:0" "_SPLIT_GRIDS\%%~nf-01.png"
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:iw/2:0" "_SPLIT_GRIDS\%%~nf-02.png"
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:0:ih/2" "_SPLIT_GRIDS\%%~nf-03.png"
  ffmpeg.exe -n -i "_RAW_GRIDS/%%f" -vf "crop=iw/2:ih/2:iw/2:ih/2" "_SPLIT_GRIDS\%%~nf-04.png"
)
pause

Example Setup

MidJourney Images\
   split-grids.bat    <--- the batch file you create
   _RAW_GRIDS\        <--- directory of your grids
      grid.png
      ...etc...
   _SPLIT_GRIDS\      <--- split grids will be stored here
      grid-01.png
      grid-02.png
      ...etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment