Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created September 19, 2015 16:55
Show Gist options
  • Save dtinth/037d52159eef08daf590 to your computer and use it in GitHub Desktop.
Save dtinth/037d52159eef08daf590 to your computer and use it in GitHub Desktop.
Crop to 4:3, add letterbox with dimmed, blurred background

Install mpv and vapoursynth:

brew tap mpv-player/mpv
brew install --with-libbs2b --with-vapoursynth mpv

Save the script below (squareize.py).

Use mpv to encode the video:

mpv src/LastMaid512.mov -vf vapoursynth=squareize.py -o BGA_another_mb.mov
import vapoursynth as vs
core = vs.get_core()
clip = video_in
# step 1: crop from 16:9 to 4:3
adjusted_width = int(clip.height * 4 / 3)
middle = core.std.CropAbs(clip, adjusted_width, clip.height, int((clip.width - adjusted_width) / 2), 0)
# step 2: scale down to 512x384
middle = core.resize.Bicubic(middle, 512, 384)
# step 3: crop to 1:1
background = core.std.CropAbs(middle, 384, 384, int((512 - 384) / 2), 0)
# step 4: blur
background = core.resize.Bicubic(background, 8, 8)
background = core.resize.Bicubic(background, 512, 512)
# step 5: dim
background = core.std.Expr([background], ["x 3 /", "", ""])
# step 6: slice to top and bottom
top = core.std.CropAbs(background, 512, 64, 0, 0)
bottom = core.std.CropAbs(background, 512, 64, 0, 512 - 64)
# step 7: stack them together
output = core.std.StackVertical([top, middle, bottom])
# step 8: output!
output.set_output()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment