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
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.mp4Both 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
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.mp4A 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
| Flag | What it does | Used here |
|---|---|---|
scale=540:960 | Brings every input to the same size first | All |
hstack=inputs=2 | Joins inputs left to right; they must have the same height | Side by side |
vstack=inputs=2 | Joins inputs top to bottom; they must have the same width | Stacked |
xstack=inputs=4:layout=... | Places each input at the position given in layout | Grid |
0_0|w0_0|0_h0|w0_h0 | Top-left, right of input 0, below input 0, diagonal from input 0 | Grid |
shortest=1 | Ends the stack when the shortest input ends | All |
force_original_aspect_ratio=increase,crop=540:960 | Scales to cover the box, then crops the overflow | Grid |
setsar=1 | Marks the pixels as square after scaling | Grid |
-map 0:a ... -shortest | Keeps the first clip's audio and cuts it to the video | Side 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.
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"]
}'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.
- Picture-in-picture video with ffmpegPut one video in the corner of another with scale, pad and overlay, end it with the main clip, or bring the inset in later.
- Resize a video with ffmpegScale a video with scale=w:h: keep the aspect ratio with -2, fit a 1080x1920 frame with pad, and fix the odd-size error.
- Crop a video with ffmpegCut a frame down with crop=w:h:x:y: a centered 9:16 or square crop, a fixed region, and cropdetect to find black bars.
- Concatenate videos with ffmpegJoin clips with the concat demuxer and -c copy when they match, or with the concat filter when their size, frame rate or codec differ.
- Trim a video with ffmpegCut a clip with -ss and -to: frame-exact with a re-encode, fast with -c copy, and why the copy starts before your time.
- ffmpeg -filter_complex explainedLabels, commas and semicolons: how a filtergraph wires inputs to outputs, with four working graphs and the errors they fix.
- FFmpeg onlineRun your own ffmpeg command on your files in the browser, free and without installing or uploading anything.
- ReelSDK vs self-hosted FFmpegTranscoding a minute of 1080p to 720p takes about 24 seconds of compute: about 0.8 cents on ReelSDK, about a tenth of a cent on a busy 4 vCPU box. Below about 11,000 minutes a month, the API costs less than an always-on box.
Sources, checked November 2026
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
