Skip to content

Rotate a video with FFmpeg

Rotating a video is a common task in video editing and production. Whether you're fixing a video that was recorded in the wrong orientation, creating a special effect, or adjusting content for different display formats, FFmpeg provides powerful tools to rotate videos quickly and efficiently. This guide will walk you through various methods of rotating videos using FFmpeg, a versatile command-line tool for handling multimedia files.

LinkWhy you may want to rotate your video

There are several reasons why you might need to rotate a video:

  • Correcting orientation: Fix videos recorded in the wrong orientation, such as sideways or upside down.
  • Artistic effects: Create unique visual effects by rotating footage for creative projects.
  • Platform requirements: Adjust videos to meet specific platform or app display requirements.
  • Vertical video adaptation: Convert horizontal videos to vertical format for platforms like TikTok or Instagram Stories.
  • Fixing metadata issues: Some devices may record correct orientation in metadata, but the video appears rotated in certain players.
  • Preparing for projection: Adjust video orientation for unusual projection setups or installations.

Let's explore how to use FFmpeg to rotate videos in various scenarios.

LinkBasic video rotation

The simplest way to rotate a video is to use FFmpeg's transpose filter. Here are commands for common rotations:

LinkRotate 90 degrees clockwise

bash
ffmpeg -i input_video.mp4 \ -vf "transpose=1" \ <{transcode_options}> \ output.mp4

LinkRotate 90 degrees counterclockwise

bash
ffmpeg -i input_video.mp4 \ -vf "transpose=2" \ <{transcode_options}> \ output.mp4

LinkRotate 180 degrees

bash
ffmpeg -i input_video.mp4 \ -vf "transpose=2,transpose=2" \ <{transcode_options}> \ output.mp4

Breakdown of the command:

  • -i input_video.mp4: Specifies the input video file
  • -vf: Applies video filters
  • transpose=1: Rotates 90 degrees clockwise
  • transpose=2: Rotates 90 degrees counterclockwise
  • <{transcode_options}> is a placeholder for encoder options (codec, frame_rate, etc.)
  • output.mp4: Name of the output file

LinkFlipping videos

Sometimes you may need to flip a video horizontally or vertically:

LinkFlip horizontally (mirror effect)

bash
ffmpeg -i input_video.mp4 \ -vf "hflip" \ <{transcode_options}> \ output.mp4

LinkFlip vertically

bash
ffmpeg -i input_video.mp4 \ -vf "vflip" \ <{transcode_options}> \ output.mp4

After you have created rotated your video you may be interested in the Mux Video API for video encoding, storage and delivery.

Learn more about Mux Video

LinkAdvanced rotation techniques

LinkRotating by arbitrary angles

For rotations other than 90-degree increments:

bash
ffmpeg -i input_video.mp4 \ -vf "rotate=45*PI/180" \ <{transcode_options}> \ output.mp4

This command rotates the video by 45 degrees. Adjust the number before *PI/180 to change the rotation angle.

LinkHandling metadata rotation

Some videos may appear rotated due to metadata. To fix this:

bash
ffmpeg -i input_video.mp4 \ -c copy -metadata:s:v:0 rotate=0 \ output.mp4

This command corrects the rotation metadata without re-encoding the video.

LinkChoosing the right approach

Different rotation techniques have various benefits and drawbacks:

Using transpose filter:

  • Benefits:
    • Simple and fast
    • Maintains video quality
  • Drawbacks:
    • Limited to 90-degree rotations

Arbitrary angle rotation:

  • Benefits:
    • Allows for any rotation angle
    • Can create unique effects
  • Drawbacks:
    • May introduce some quality loss
    • Can change video dimensions

Metadata correction:

  • Benefits:
    • Very fast, no re-encoding required
    • Preserves original video quality
  • Drawbacks:
    • Only works for metadata-based rotation issues
    • May not be supported by all video players

LinkMux tips for effective video rotation

  1. Check your source: Ensure you're working with the highest quality source video available.
  2. Consider aspect ratio: Rotation may change the aspect ratio of your video. Plan accordingly for your target platform.
  3. Test output: Always preview the rotated video to ensure it meets your requirements.
  4. Mind the file size: Some rotation methods may increase file size. Adjust encoding settings if needed.
  5. Use lossless rotation when possible: For 90-degree rotations, use methods that don't require re-encoding to maintain quality.
  6. Batch processing: For multiple files, consider writing a script to automate the rotation process.
  7. Preserve metadata: Use the -map_metadata 0 option to keep relevant metadata from the original file.

LinkVideo rotation FAQs

Will rotating a video reduce its quality?

Using the transpose filter for 90-degree rotations maintains quality because it's a lossless geometric transformation. However, rotating by arbitrary angles (like 45 degrees) introduces interpolation that can slightly reduce quality. To minimize quality loss, use high-quality encoding settings and avoid rotating multiple times—plan your final orientation and rotate once from the source file.

Can I rotate a video without re-encoding it?

Only if the rotation issue is purely metadata-based. Use -c copy -metadata:s:v:0 rotate=0 to strip incorrect rotation metadata without re-encoding. This is extremely fast and preserves perfect quality. However, if the video pixels themselves need rotation (not just metadata), re-encoding is required. The transpose filter is your best option for maintaining quality during actual pixel rotation.

Why does my rotated video have black bars?

Black bars appear when rotating by arbitrary angles because the rotated frame doesn't fit perfectly within the original rectangular dimensions. The rotate filter adds padding to maintain the full rotated image. To remove black bars, crop the video after rotation using the crop filter, though this reduces the visible area. For 90-degree rotations with transpose, the output dimensions automatically adjust and no black bars appear.

How do I batch rotate multiple videos?

Write a shell script that loops through video files and applies the same FFmpeg command to each. For example: for file in *.mp4; do ffmpeg -i "$file" -vf "transpose=1" "rotated_$file"; done. This rotates all MP4 files in a directory 90 degrees clockwise. Adjust the transpose value or filter as needed for your use case.

What's the difference between transpose and rotate filters?

The transpose filter only handles 90-degree increments (and flips) but is optimized, fast, and maintains perfect quality. The rotate filter accepts any angle in radians but uses interpolation that can introduce slight quality loss and may add black padding. Use transpose for 90/180/270-degree rotations and rotate only when you need arbitrary angles.

Does rotation affect video playback performance?

The rotation process itself affects encoding time, not playback performance. Once encoded, a rotated video plays exactly like any other video—the player doesn't need to perform rotation in real-time. However, if you rotate to an unusual resolution (like making a 1920x1080 video into 1080x1920), playback performance depends on the viewer's device capabilities for that resolution, not the rotation itself.

How do I fix videos that appear sideways on some devices but not others?

This typically indicates a metadata rotation issue. Different players handle rotation metadata differently—some respect it, others ignore it. To fix this permanently, rotate the actual pixels using transpose and strip the metadata: ffmpeg -i input.mp4 -vf "transpose=1" -metadata:s:v:0 rotate=0 output.mp4. This ensures the video appears correctly on all devices regardless of metadata support.

Arrow RightBack to Articles

No credit card required to start using Mux.