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

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

LinkTips 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.


No credit card required to start using Mux.