Rotating and Shrinking Video: One First with FFmpeg

Abstract: Apply FFmpeg transpose and scale filters in correct order to rotate video and reduce file size without distortion.

Created: 2026-08-06 by

Use the transpose and scale video filters in FFmpeg to rotate and shrink a video simultaneously. The command ffmpeg -i input.mp4 -vf "transpose=1,scale=iw/2:ih/2" output.mp4 rotates the clip 90 degrees clockwise and reduces its dimensions by half, ensuring the file size decreases while maintaining visual clarity through proper encoding settings.

Understanding Filter Chains and Order of Operations

When manipulating video streams with FFmpeg, the order in which you apply filters matters significantly for both performance and final output quality. Video filters are processed sequentially from left to right within the filter graph. If you attempt to scale a video before rotating it, the scaling engine works on the original width and height. This often results in an incorrect aspect ratio or unintended black bars if the rotation changes the orientation from landscape to portrait, or vice versa. By placing the transpose filter first, you ensure that the subsequent scale filter receives the already rotated frame dimensions. For example, if you have a standard 1920x1080 landscape video and you want to rotate it 90 degrees clockwise to make it portrait, the transpose filter converts the logical dimensions to 1080x1920. When the scale filter then runs, it correctly interprets these new dimensions. If you had scaled first, you might end up scaling the wrong axis, leading to stretched or distorted visuals. This principle applies to all complex filter chains. Always visualize the data flow: input frames enter the first filter, get modified, pass to the second, and so on until the output is generated. In our specific case of shrinking and rotating, the rotation must precede the scaling to guarantee that the reduction factor applies to the correct geometric axes. This prevents the common error where users wonder why their portrait video still has excessive horizontal padding after processing.

Choosing the Right Transpose Values

The transpose filter supports several integer values that dictate how the video frame is rotated and flipped. Understanding these options is crucial because not all rotations are simple 90-degree turns; some involve mirroring as well.
  • 0: Rotates 90 degrees counter-clockwise and flips vertically. This is often used when converting between landscape and portrait orientations without changing the pixel data layout excessively.
  • 1: Rotates 90 degrees clockwise. This is the most common choice for making a landscape video into a vertical portrait video for mobile platforms.
  • 2: Rotates 90 degrees counter-clockwise. This mirrors the effect of value 1 but without the vertical flip.
  • 3: Rotates 90 degrees clockwise and flips vertically.
If your goal is simply to reduce the file size and change orientation, transpose=1 is typically the safest bet for social media uploads. However, be aware that flipping can sometimes introduce artifacts depending on the source codec. If you notice visual glitches, try swapping between transpose values 1 and 3 to see which produces cleaner edges. For more precise control, you can combine transpose with other transformations, but keep in mind that each additional operation increases CPU load during encoding. Since we are also scaling the video, keeping the filter chain minimal helps maintain encoding speed. You do not need extra rotation steps if one transpose call achieves the desired orientation.

Scaling Strategies for Shrinking

Shrinking a video involves reducing its resolution, which directly impacts file size and bandwidth requirements. The scale filter allows you to specify exact pixel dimensions or use relative factors. Using absolute pixels like scale=720:1280 ensures a consistent output size across different source videos, which is useful for batch processing. Alternatively, using relative factors like scale=iw/2:ih/2 halves the width and height regardless of the source resolution. When shrinking, it is important to maintain the aspect ratio unless you intentionally want to distort the image. FFmpeg’s scale filter preserves aspect ratio by default if you specify only one dimension (width or height) and leave the other as -2. However, since we are rotating first, the width and height swap roles. Therefore, specifying both dimensions explicitly after rotation gives you full control over the final output shape. Quality degradation occurs when downscaling too aggressively. Reducing a 4K video to 240p will result in significant loss of detail. A good rule of thumb is to target resolutions that match the display medium. For mobile viewing, 720p or 1080p in portrait mode is usually sufficient. If you are aiming for smaller file sizes, consider lowering the bitrate instead of just the resolution, as this can preserve sharpness better than extreme downscaling. Another consideration is the scaling algorithm. FFmpeg uses bilinear interpolation by default, which is fast and adequate for most cases. For higher quality downscaling, you can add flags like flags=lanczos to the scale filter, such as scale=iw/2:ih/2:flags=lanczos. This provides sharper edges at the cost of increased encoding time. For general use cases, the default setting offers a balanced trade-off between speed and visual fidelity.

Encoding Parameters and Quality Control

Applying filters does not automatically optimize the video for storage or streaming. You must also configure the encoder parameters to manage the trade-off between file size and quality. The most critical parameter is the Constant Rate Factor (CRF), which controls the quality of H.264 or H.265 encoded videos. A CRF value of 23 is considered neutral; lower values mean higher quality and larger files, while higher values mean lower quality and smaller files. When shrinking a video, you can often increase the CRF slightly because the reduced resolution makes compression artifacts less noticeable. For example, a CRF of 25 or 28 might look perfectly fine on a small screen while producing a much smaller file than a CRF of 23. Experiment with these values to find the sweet spot for your specific content. Additionally, choose the appropriate preset for the encoder. The -preset flag in FFmpeg ranges from ultrafast to veryslow. Faster presets encode quicker but produce larger files for the same quality. Slower presets take longer but achieve better compression efficiency. For a task involving rotation and scaling, using medium or slow presets is recommended to ensure the downscaled video remains efficient. Do not forget to set the audio codec appropriately. If the source audio is AAC, you can often streamcopy it using -c:a copy to save processing time, provided the container format supports it. If re-encoding is necessary, use a reasonable bitrate like 128k or 192k for stereo audio.

Performance Considerations

Combining rotation and scaling requires computational resources. While modern CPUs handle this easily, large batches of high-resolution footage may cause bottlenecks. To mitigate this, ensure you are using hardware acceleration if available. Adding -hwaccel cuda (for NVIDIA) or -hwaccel videotoolbox (for macOS) can offload decoding and encoding tasks to the GPU. Note that not all filters support hardware acceleration, so check the FFmpeg documentation for compatibility. If you are processing multiple files, consider writing a script to automate the command generation. This avoids manual entry errors and ensures consistency across all outputs. Also, monitor disk I/O speeds, as reading and writing large video files can be slower than the actual processing. Using SSDs for temporary storage can significantly improve throughput. For further optimization, you might explore removing unnecessary frames or segments before applying heavy filters. See how to efficiently manage timestamps and inputs in related guides to streamline your workflow. Proper planning of the filter chain reduces redundant operations and saves time during long encoding sessions.

Frequently Asked Questions

Does rotating a video change its file size?

Rotation itself does not change the file size because it merely rearranges pixel data without compressing or decompressing the stream. However, when you combine rotation with scaling to shrink the video, the file size decreases due to the lower resolution and potentially adjusted bitrate. The actual savings depend on the encoder settings and the complexity of the video content.

Can I rotate a video without re-encoding?

You cannot rotate a video using filters like transpose without re-encoding, as these filters modify the pixel structure. However, some containers allow storing rotation metadata tags that players can interpret without altering the video stream. FFmpeg’s transpose filter always triggers a re-encode process to apply the geometric transformation permanently.

Why is my video blurry after shrinking?

Blurriness usually results from aggressive downscaling or low-quality scaling algorithms. Ensure you are using a decent scaling method like lanczos if quality is paramount. Additionally, check if your bitrate is too low for the new resolution; a low bitrate combined with downsampling can create blocky artifacts that appear blurry.

How do I keep the aspect ratio when shrinking?

To maintain the aspect ratio, specify only one dimension in the scale filter and use -2 for the other. For example, scale=720:-2 sets the width to 720 pixels and calculates the height automatically based on the original proportions. After rotation, the width and height definitions swap, so adjust your parameters accordingly to preserve the intended shape.

What is the best preset for fast encoding?

The ultrafast or superfast presets provide the quickest encoding speeds but result in larger file sizes for the same quality level. If speed is your primary concern and storage space is not limited, use ultrafast. For a balance between speed and compression efficiency, the medium preset is generally recommended for most user scenarios.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More