FFmpeg: How to Rotate Video on Vertical Axis to 3D Trapezoid Look

Updated

Rotate a video on its vertical axis to create a stylized 3D trapezoid effect

FFmpeg: How to Rotate Video on Vertical Axis to 3D Trapezoid Look

To follow along, you just need FFmpeg installed on your system, access to a terminal, and a video file named input.mp4 in your current folder.

1. Core Trapezoid Effect

First, let's create the core trapezoid effect. This applies a perspective filter that skews the vertical edges and draws a white border around your video.

Open your terminal and run this command:

ffmpeg -i input.mp4 -vf "drawbox=t=1:c=white,perspective=x0=0:y0=250:x1=W:y1=0:x2=0:y2=H:x3=W:y3=H-250:sense=destination" output.mp4

2. Asymmetric Version

If you want a more realistic 3D appearance rather than a flat keystone, you can use an asymmetric version that calculates frame progression.

First, count the total frames in your video with ffprobe and set a fallback value by running these lines:

F=$(ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -of csv=p=0 input.mp4)
F=${F:-1000}
ffmpeg -i input.mp4 -vf "perspective=eval=frame:x0=0:y0='400*max(0,1-in/$F)':x1=W:y1='-200*max(0,1-in/$F)':x2=0:y2=H:x3=W:y3=H:sense=destination" -c:a copy output_3d_trapezoid.mp4

Depending on your computer's speed and the length of your clip, rendering may take a minute or two, so let the terminal complete the export.

Once processing completes, do a quick test by playing output_3d_trapezoid.mp4 in your favorite video viewer or by running ffplay output_3d_trapezoid.mp4 to check the motion and perspective shift.

You can fine-tune the severity of the 3D slant by adjusting the coordinate offsets like 250 or 400 inside the filter expressions.