Skip to content
Cutfac

How to convert a horizontal video to vertical 9:16 for Shorts: three ways compared

A YouTube Short is 9:16, so a 16:9 clip doesn't fit: a vertical slice of it keeps under a third of the width. What's left is a choice. Cut to the middle, show the whole frame over a blurred copy of itself, or move the slice along with the subject. This guide follows one real run in which Claude Code made all three from the same clip with ffmpeg and compared them. Each step shows the command, what it printed, and what the filters do.

Published:

Beforevan.webm, the starting clip: 1920 × 1080 with no sound. These are the first 7 of its 9.55 seconds.
Afterfollow.mp4, 1080 × 1920: the slice moves with the van. It's one of the three versions compared below.

Shorts size: 9:16, 1080 × 1920

A YouTube Short is vertical: 9:16, which at full HD is 1080 × 1920 pixels. Google's ad specs list 1080 × 1920 as the recommended HD size for 9:16 and recommend 9:16 for Shorts. What YouTube's help says counts as a Short:

  • Square or vertical. A video in either shape can be a Short.
  • Up to 3 minutes. Square and vertical videos up to 3 minutes long, uploaded on or after October 15, 2024, are categorized as Shorts.
  • Up to 1080p. That's the highest resolution YouTube takes for a Short.
  • A 16:9 video stays long-form. YouTube's advice for a video you don't want classified as a Short is a wider ratio such as 16:9.

What we're making

The starting point is “Volkswagen T2” from Wikimedia Commons, released under CC0, so it can be used without credit. In 9.55 seconds of 1920 × 1080 video with no sound, a white van appears far down a concrete road at the right and drives toward the camera, leaving the frame at the bottom left after about 7 seconds.

A 9:16 slice of a 1080-pixel-tall frame is 608 pixels wide, under a third of the picture, and the van crosses nearly all of it. The guide on making Shorts with Claude Code, with the Shibuya Crossing clip, picked one fixed slice; that works when what matters stays in place. Here it doesn't, so the goal is three versions to compare: a center crop, the whole frame over a blurred background, and a crop that follows the van. The last one is at the top of the page, next to the clip it started from.

Every command, output and frame below comes from that run. All three versions stop at 7 seconds; step 5 shows why.

What you need

A Mac with Homebrew, Claude Code signed in with your own account, and an empty folder to work in. Here's what each part does:

  • Claude Code: the agent. It writes and runs the commands, reads what the tracker found, and looks at frames from each version.
  • ffmpeg: converts video. Cropping, scaling, blurring, layering and putting videos side by side are all ffmpeg filters. ffprobe, which comes with it, reads what's in a file.
  • uv: runs a Python script with the packages it needs in an environment of its own, so nothing is installed into your system's Python. It's free under the MIT or Apache 2.0 license.
  • OpenCV: a computer vision library, free under the Apache 2.0 license. Its CSRT tracker follows a box from frame to frame. uv downloads it the first time the script runs.
  • python3, for the second script, comes with Apple's Command Line Tools, which Homebrew needs anyway.

Step 1: Install ffmpeg and uv, get the clip

Homebrew installs both:

brew install ffmpeg uv

Commons serves the original as an 8.2 MB WebM file:

curl -L -o van.webm "https://upload.wikimedia.org/wikipedia/commons/2/2e/Volkswagen_T2.webm"

ffprobe shows what's in it: VP8 video at 1920 × 1080, 24000/1001 frames a second (about 23.976), 9.55 seconds long. There's no audio stream, so none of the commands below has audio options.

ffprobe -v error -show_entries stream=codec_name,width,height,r_frame_rate:format=duration -of compact=p=0 van.webm
codec_name=vp8|width=1920|height=1080|r_frame_rate=24000/1001
duration=9.551000

Step 2: Brief Claude Code

Open Claude Code in the folder. The brief names the three versions and how to check them, and leaves the commands to Claude Code:

Claude Code

van.webm is a 16:9 clip of a van driving toward the camera. Make three 1080 × 1920 versions for Shorts with ffmpeg: - center.mp4: a center crop - blur.mp4: the whole frame over a blurred copy of itself - follow.mp4: a crop that follows the van. Track it with OpenCV and run the script with uv - Make all three the same length and check frames from each - Put them side by side and tell me which works for this clip

The three take different amounts of work. The center crop is one filter, and the blurred background is a small filter graph. The following crop needs to know where the van is in every frame, which is what the tracker is for.

Step 3: Center crop

One ffmpeg command crops, scales and encodes:

ffmpeg -i van.webm -t 7 -vf "crop=ih*9/16:ih,scale=1080:1920" -c:v libx264 -crf 20 -pix_fmt yuv420p center.mp4

crop=ih*9/16:ih keeps the full height and a width of 9/16 of it, 608 pixels. Without an x and a y, crop centers the slice, (1920 − 608) / 2 = 656 pixels from the left. scale=1080:1920 enlarges it to Shorts size. -t 7 keeps the first 7 seconds, -crf 20 sets the quality and -pix_fmt yuv420p keeps the H.264 file playable everywhere. It took 1.3 seconds. Here's where that slice falls on four frames of the clip:

Four frames of the clip in a grid at 0, 2, 4 and 6 seconds, each with its middle third bright and the rest dimmed. The van is right of the bright slice at 0, 2 and 4 seconds; at 6 its front has reached it.
The center slice, bright, at 0, 2, 4 and 6 seconds.

The van starts outside the slice and only drives into it at about 5 seconds. Until then, the center crop shows an empty road and water. After that, the van is cut off at the slice's right edge:

Three vertical frames from center.mp4. At 2 seconds, water, posts and an empty road. At 5.5, the front of the van at the right edge, half cut off. At 6.5, the van fills the bottom, cut off at the right.
center.mp4 at 2, 5.5 and 6.5 seconds.

The Shibuya guide compared four slices of one frame and kept the one at 450 pixels for the whole clip. The van moves across the whole width, so no fixed slice holds it from start to end.

Step 4: Blurred background

The second version keeps the whole frame. It sits in the middle of the vertical frame at full width, and a blurred, enlarged copy of the same video fills the space above and below it:

ffmpeg -i van.webm -t 7 -filter_complex \  "[0:v]split[a][b];[a]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,gblur=sigma=40[bg];[b]scale=1080:-2[fg];[bg][fg]overlay=(W-w)/2:(H-h)/2" \  -c:v libx264 -crf 20 -pix_fmt yuv420p blur.mp4

-filter_complex takes a graph of filters, with names in brackets for what passes between them. split makes two copies of the video, [a] and [b]. [a] is scaled until it covers 1080 × 1920 (force_original_aspect_ratio=increase), cropped to exactly that, and blurred with gblur, a Gaussian blur, where sigma=40 sets how strong. That's the background, [bg]. [b] is scaled to 1080 wide with its shape kept, which makes it 1080 × 608 (-2 picks a height divisible by 2). overlay puts it in the middle of the background. It took 1.5 seconds.

Claude Code first used boxblur, which averages a square of pixels, and its frames looked blocky. gblur's blur is smooth:

Three vertical frames from blur.mp4. In each, the full landscape frame sits in a band across the middle, with a blurred, enlarged copy of it above and below. The van is small in the band; at 6.5 seconds a blurred copy of it fills the bottom.
blur.mp4 at 2, 5.5 and 6.5 seconds.

Nothing is cut off, but the picture fills 608 of the 1920 rows, under a third of the screen, so the van is small on a phone. Google does the same with ads: its Shorts ad specs say horizontal assets serve in a vertical Short with blurred tops and bottoms.

Step 5: A crop that follows the van

To follow the van, the crop has to know where it is in every frame. A tracker does that: given a box around something in the first frame, it finds the same thing in each frame after. Claude Code looked at an enlarged crop of the first frame, read the van's box as 115 × 90 pixels at x 1645, y 588, and wrote track.py with OpenCV's CSRT tracker:

# Follow one box through a video and print where it is in every frame.# usage: track.py VIDEO X Y W H > track.csv   (X Y W H: the subject's box in frame 1)import sysimport cv2video = sys.argv[1]box = tuple(int(v) for v in sys.argv[2:6])cap = cv2.VideoCapture(video)ok, frame = cap.read()tracker = cv2.TrackerCSRT_create()tracker.init(frame, box)print("frame,time,found,x,y,w,h")n = 0while ok:    found, (x, y, w, h) = (True, box) if n == 0 else tracker.update(frame)    seconds = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000    print(f"{n},{seconds:.3f},{int(found)},{x},{y},{w},{h}")    n += 1    ok, frame = cap.read()

uv run --with opencv-contrib-python makes an environment with OpenCV's Python package and runs the script in it. The first run downloaded OpenCV (53.1 MiB) and NumPy (5.2 MiB) and took about 18 seconds; later runs took about 3.5:

uv run --with opencv-contrib-python python track.py van.webm 1645 588 115 90 > track.csv

track.csv has one row per frame. Some of them:

sed -n '1,2p;50p;98p;146p;170p;177,179p' track.csv
frame,time,found,x,y,w,h
0,0.000,1,1645,588,115,90
48,2.002,1,1575,609,152,119
96,4.004,1,1385,622,239,187
144,6.006,1,884,714,342,267
168,7.007,1,213,895,316,247
175,7.299,1,-87,903,303,237
176,7.341,0,0,0,0,0
177,7.382,1,5,-119,303,237

The box grows as the van comes closer, from 115 pixels wide to 342 at 6 seconds. At 7.3 seconds x goes negative as the van leaves the frame, and at 7.34 found turns 0: the tracker lost it. One frame later it reports found again, but at y −119, above the top of the frame, and to the end of the clip its box sits in the sky. found only means the tracker found something, not that it's the van. So all three versions stop at 7 seconds, while the tracker still has it.

The boxes also jump a little from frame to frame, and a crop that followed them exactly would shake. path.py, which needs only Python's standard library, turns them into a smooth path:

# Turn tracked boxes into a smooth crop path for ffmpeg's sendcmd filter.# usage: path.py track.csv SECONDS > crop.cmdimport csvimport sysSOURCE_W, CROP_W = 1920, 608  # a 9:16 slice of a 1080-pixel-tall frameHALF = 6  # average each frame with 6 before and 6 after it, about half a second in allrows = list(csv.DictReader(open(sys.argv[1])))keep = [r for r in rows if float(r["time"]) < float(sys.argv[2])]# The average near the end also reads a few frames past it, so the slice doesn't lag behind.centers = [float(r["x"]) + float(r["w"]) / 2 for r in rows[: len(keep) + HALF]]for i, row in enumerate(keep):    near = centers[max(0, i - HALF) : i + HALF + 1]    left = sum(near) / len(near) - CROP_W / 2    left = min(max(left, 0), SOURCE_W - CROP_W)  # keep the slice inside the frame    print(f"{row['time']} crop x {round(left)};")

For each frame it averages the box's center with 6 frames before and 6 after, about half a second, and centers the 608-pixel slice on that, kept between 0 and 1312 so it never leaves the frame. Near the 7-second cut it also reads frames past it. Without them, the last averages would hold only earlier frames and the slice would lag behind the van. It writes one line per frame, in the form ffmpeg's sendcmd filter reads:

python3 path.py track.csv 7 > crop.cmd
sed -n '1p;73p;97p;121p;145p;168p' crop.cmd
0.000 crop x 1312;
3.003 crop x 1298;
4.004 crop x 1201;
5.005 crop x 1035;
6.006 crop x 746;
6.965 crop x 94;

sendcmd reads crop.cmd and, at each time in it, sends the crop filter a new x. crop accepts that as a command while the video plays, so the slice moves. crop=608:1080:1312:0 sets the size and the position it starts at:

ffmpeg -i van.webm -t 7 -vf "sendcmd=f=crop.cmd,crop=608:1080:1312:0,scale=1080:1920" -c:v libx264 -crf 20 -pix_fmt yuv420p follow.mp4

It took 1.3 seconds. Here's the moving slice on the same four frames, with the tracker's box:

The same four frames at 0, 2, 4 and 6 seconds, each with one bright vertical slice and a yellow box around the van. At 0 seconds the slice is against the right edge with the van right of its middle; at 2 and 4 the van is near the middle, and at 6 the slice has moved left with it.
The slice that follows the van, bright, and the tracker's box at 0, 2, 4 and 6 seconds.

For the first 3 seconds the slice stays at 1312, against the right edge. At the start, the van's center is 218 pixels from that edge, less than half a slice, so it sits right of the slice's middle. Then the slice moves left with the van, about 1,200 pixels in 4 seconds:

Three vertical frames from follow.mp4. At 2 seconds the van is small on the road near the middle, with a person at the right edge. At 5.5 it's large and centered. At 6.5 its front fills the bottom and its side runs off the right edge.
follow.mp4 at 2, 5.5 and 6.5 seconds.

At 6.5 seconds the van is wider than the slice, so only its front fits. No 9:16 crop of this clip can do better there: up close, the van is wider than 608 pixels.

Step 6: Compare them side by side

hstack puts videos of the same height next to each other, so one 3240 × 1920 file plays all three at once. It took 3.6 seconds and made 11.9 MB:

ffmpeg -i center.mp4 -i blur.mp4 -i follow.mp4 -filter_complex hstack=inputs=3 -c:v libx264 -crf 20 -pix_fmt yuv420p compare.mp4

Then one check that every file has the size and length it should: 1080 × 1920, or 3240 × 1920 for the comparison, with 168 frames and 7.007 seconds each:

for f in center blur follow compare; do  ffprobe -v error -select_streams v:0 -show_entries stream=width,height,nb_frames:format=duration -of csv=p=0 $f.mp4done
1080,1920,168
7.007000
1080,1920,168
7.007000
1080,1920,168
7.007000
3240,1920,168
7.007000
compare.mp4, scaled down and spaced out for this page. Left to right: the center crop, the blurred background and the crop that follows the van.

Which one to use

For this clip, the crop that follows the van. It has the van from the first second, while the center crop shows an empty road for 5 seconds and the blurred version shows the van small. Other clips suit the other two:

  • Center crop, or a fixed slice like the Shibuya one: when what matters stays in one place. It's one filter and the quickest to make.
  • Blurred background: when the whole frame matters and it's fine for it to be small, such as a wide shot whose layout is the point.
  • A crop that follows the subject: when one subject moves across the frame, as the van does here.

Where it gets hard

The tracker started from one look at the first frame, and it went wrong without saying so: at 7.3 seconds it lost the van and moved to the sky while still reporting found. Reading the rows and the frames caught it. A real video has many shots, and each needs its own choice of crop, its own box and its own check. With more videos, finding the moment and saying what's wrong with it is most of the work.

Cutfac is a Mac app we make for that part. It runs Claude Code or Codex for each video, lets you select a range or draw a box on the frame and say what to change, and keeps versions side by side to compare and pick from. You can do everything in this guide without it.

Free tools for this

Sources

Questions