Scale both inputs to the same height, then hstack: two 1080x1920 clips at 540x960 each make one 1080x960 video. A 10-second pair costs under a third of a cent through ReelSDK ($0.02 a compute minute), and mismatched heights stop with an error.

Put two videos side by side with ffmpeg

hstack joins videos left to right, vstack top to bottom, xstack in a 2x2 or any other grid; none of them resize. ReelSDK's API had our 1080x960 pair done in about 9 seconds, with shortest=1 cutting it to the shorter clip.

GuidesUpdated

hstack
ffmpeg -i left.mp4 -i right.mp4 -filter_complex \
  "[0:v]scale=540:960[l];[1:v]scale=540:960[r];[l][r]hstack=inputs=2:shortest=1[v]" \
  -map "[v]" -map 0:a -c:v libx264 -crf 20 -c:a copy -shortest sbs.mp4

Both clips are scaled to 540x960 and joined left to right. shortest=1 and -shortest end the result with the shorter clip; the left clip's audio is kept.

Variations

The other commands you will need

  1. On top of each other

    vstack needs the same width instead of the same height. The pair became 540x1920.

    vstack
    ffmpeg -i left.mp4 -i right.mp4 -filter_complex \
      "[0:v]scale=540:960[t];[1:v]scale=540:960[b];[t][b]vstack=inputs=2:shortest=1[v]" \
      -map "[v]" -map 0:a -c:v libx264 -crf 20 -c:a copy -shortest stacked.mp4
  2. A 2x2 grid

    xstack places each input by layout. The fourth clip is landscape, so it is scaled to cover 540x960 and cropped.

    xstack
    ffmpeg -i a.mp4 -i b.mp4 -i c.mp4 -i d.mp4 -filter_complex \
      "[0:v]scale=540:960,setsar=1[a];[1:v]scale=540:960,setsar=1[b];[2:v]scale=540:960,setsar=1[c];\
       [3:v]scale=540:960:force_original_aspect_ratio=increase,crop=540:960,setsar=1[d];\
       [a][b][c][d]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0:shortest=1[v]" \
      -map "[v]" -c:v libx264 -crf 20 grid.mp4

The flags

The options in these commands

The options in these commands
FlagWhat it doesUsed here
scale=540:960Brings every input to the same size firstAll
hstack=inputs=2Joins inputs left to right; they must have the same heightSide by side
vstack=inputs=2Joins inputs top to bottom; they must have the same widthStacked
xstack=inputs=4:layout=...Places each input at the position given in layoutGrid
0_0|w0_0|0_h0|w0_h0Top-left, right of input 0, below input 0, diagonal from input 0Grid
shortest=1Ends the stack when the shortest input endsAll
force_original_aspect_ratio=increase,crop=540:960Scales to cover the box, then crops the overflowGrid
setsar=1Marks the pixels as square after scalingGrid
-map 0:a ... -shortestKeeps the first clip's audio and cuts it to the videoSide by side, stacked

Sources: ffmpeg filters: hstack, ffmpeg filters: vstack, ffmpeg filters: xstack, checked November 2026.

The height error

hstack does not resize anything. Give it a 1920x1080 clip and a 1080x1920 clip and it stops with "Input 1 height 1920 does not match input 0 height 1080". vstack fails the same way on widths.

Scale first. For two vertical clips, 540x960 each gives a 1080x960 result, half the size of either source in each direction. If the clips have different shapes, scale them to the same height and let the widths differ, or use force_original_aspect_ratio=increase and crop to fill the same box, as in the grid.

Which clip sets the length

Our left clip runs a fifth of a second longer than the right one. Without shortest=1, the stack ran as long as the longer one; with it, the stack stops when the right clip ends. -shortest on the output then cuts the copied audio to match.

For a comparison video, ending with the shorter clip is usually right. For a reaction video, trim the clips to the same length first instead; see trimming with ffmpeg.

Reading an xstack layout

Each entry in layout is the position of one input, separated by |, written as x and y joined by an underscore. w0 and h0 mean the width and height of input 0. So 0_0|w0_0|0_h0|w0_h0 puts four equal clips in a 2x2 grid: 1080x1920 for four 540x960 inputs.

Our grid mixed three vertical clips with one landscape clip. Scaling the landscape one to cover 540x960 and cropping the overflow kept the cells the same size; scaling it straight to 540x960 would have squeezed it.

Without installing ffmpeg

The same command as one API call

Send the same args to POST /v1/ffmpeg with both video URLs in inputs. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; this one finished in about 9 seconds and cost under a third of a cent.

terminalTry it
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
  -H "Authorization: Bearer $REELSDK_KEY" \
  --json '{
    "inputs": {
      "left.mp4": "https://api.reelsdk.com/f/lib/demo/clip.mp4",
      "right.mp4": "https://api.reelsdk.com/f/out/job_o5kpzf5opqvopafnvlpd/video.mp4"
    },
    "args": [
      "-i", "left.mp4", "-i", "right.mp4", "-filter_complex",
      "[0:v]scale=540:960[l];[1:v]scale=540:960[r];[l][r]hstack=inputs=2:shortest=1[v]",
      "-map", "[v]", "-map", "0:a", "-c:v", "libx264", "-crf", "20", "-c:a",
      "copy", "-shortest", "sbs.mp4"
    ],
    "outputs": ["sbs.mp4"]
  }'
Two 1080x1920 clips, scaled to 540x960 and joined into 1080x960, as long as the shorter clip.Input: left clipright clip

FAQ

Questions, answered

How do I put two videos side by side with ffmpeg?

Scale both to the same height and use hstack: ffmpeg -i a.mp4 -i b.mp4 -filter_complex "[0:v]scale=-2:960[l];[1:v]scale=-2:960[r];[l][r]hstack=inputs=2:shortest=1" out.mp4.

Why does hstack say the height does not match?

hstack needs every input at the same height (vstack: the same width). Scale the inputs before stacking them.

How do I make a 2x2 video grid with ffmpeg?

Scale four inputs to one size and use xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0.

Can I join videos side by side with an API?

Yes. POST the same args to https://api.reelsdk.com/v1/ffmpeg with both video URLs in inputs. It runs ffmpeg 8.1 for $0.02 per compute minute, billed per second.

Ready to build?

Ship video from your app today

Your first $0.50 is free, and one key covers every endpoint.

Moonlit lake with a lit cabin under the mountains