How to Rotate Video and Change Background Color in FFmpeg

Rotating a video often alters its aspect ratio, which can result in empty spaces or black bars on the sides of the frame. This guide demonstrates how to use FFmpeg to rotate a video and customize the background color of those newly created empty areas using a single command.

Step 1: The Basic Command Structure

To rotate a video and fill the surrounding empty space with a specific color, you must combine the transpose filter (for rotation) and the pad filter (for adding the background color) within a video filter chain (-vf).

Here is the standard command:

ffmpeg -i input.mp4 -vf "transpose=1,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=blue" output.mp4

Step 2: Understanding the Parameters

To customize this command for your specific video, you need to understand how the filters work:

Example: Rotating Landscape to Portrait with a Gray Background

If you have a standard 1920x1080 landscape video, rotate it 90 degrees clockwise to make it portrait, and want to pad the sides to maintain a 1920x1080 frame with a dark gray background, use this command:

ffmpeg -i input.mp4 -vf "transpose=1,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=0x1A1A1A" -c:a copy output.mp4

In this command, -c:a copy is added to copy the audio stream without re-encoding it, which speeds up the rendering process.