Creating Portrait and Landscape Video Set Images with FFmpeg: A Simple Guide

Abstract: Resolves FFmpeg hstack height mismatch errors by scaling portrait and landscape videos to a common height for side-by-side composite images.

Created: 2026-10-23 by
Use FFmpeg to generate composite images from video frames by scaling portrait and landscape clips to a common height, padding the shorter aspect ratio with black bars, and then stacking them horizontally using the hstack filter. This approach ensures that both video streams align perfectly on the Y-axis regardless of their original resolution, creating a side-by-side preview suitable for social media or catalog thumbnails.

Understanding the Aspect Ratio Challenge

When combining vertical (portrait) and horizontal (landscape) video content into a single image, the primary technical hurdle is the mismatch in dimensions. Portrait videos typically have a 9:16 aspect ratio, while landscape videos follow a 16:9 ratio. If you attempt to stack these directly using the hstack filter without preprocessing, FFmpeg will fail because the filter requires all input streams to have identical heights. A naive approach might scale both to an arbitrary small number, such as 180 pixels, but this ignores the fact that the resulting widths will differ significantly, potentially leading to distorted visuals or misaligned elements if not handled correctly.

To solve this, we must normalize the height first. By forcing both inputs to share the same pixel height, we guarantee compatibility with the stacking operation. The width will naturally vary based on the aspect ratio, which is acceptable since hstack only cares about vertical alignment. We can then add padding to the narrower frame so that it matches the width of the wider frame, or simply let the stacked result be the sum of the two widths. For most thumbnail use cases, keeping the height uniform and allowing variable width is the cleanest solution.

Extracting Frames from a Video using FFmpeg provides the foundational step of getting individual images from your source files, which is often necessary before applying complex filters like hstack. Once you have isolated the specific moments you want to showcase, you can proceed with the compositing logic described below.

Step-by-Step Implementation

The following command demonstrates how to extract a frame from a portrait video and a landscape video, resize them to a standard height, pad the portrait video to match the landscape width, and finally merge them. In this example, we target a standard output height of 360 pixels, which corresponds to the 360p resolution often used for web previews.

ffmpeg -i portrait.mp4 -i landscape.mp4 \
-filter_complex "[0:v]scale=-1:360,pad=width=ih*16/9:height=360:x=(ow-iw)/2:y=0:black[v0]; [1:v]scale=-1:360[v1]; [v0][v1]hstack" \
frames.jpg

Let us break down the -filter_complex argument, as this is where the magic happens. The filter chain operates on three distinct stages: scaling, padding, and stacking.

1. Scaling to Common Height

The scale=-1:360 instruction tells FFmpeg to set the height to exactly 360 pixels. The width is calculated automatically (-1) to maintain the original aspect ratio. This ensures that the portrait clip becomes narrow but tall enough, and the landscape clip becomes wide but equally tall. Without this step, the hstack filter would reject the inputs due to height mismatch.

2. Padding for Alignment

Although hstack does not strictly require equal widths, padding improves visual consistency. In the example above, we assume the landscape video is the reference for width. However, a more robust method is to calculate the maximum width required. Since landscape is 16:9 and portrait is 9:16, at 360px height, the landscape width is 640px and the portrait width is 240px. To center the portrait within a 640px box, we use pad=width=640:height=360:x=(ow-iw)/2:y=0:black. This adds black bars to the left and right of the portrait video, making it appear as a centered element rather than a tiny strip.

If you do not wish to pad and just want them side-by-side regardless of width differences, you can skip the pad filter entirely. The hstack filter will still work as long as the heights are equal. The resulting image will simply be 880 pixels wide (640 + 240).

3. Horizontal Stacking

The final part, [v0][v1]hstack, takes the processed portrait stream labeled v0 and the landscape stream labeled v1 and places them next to each other. The labels [v0] and [v1] are crucial; they allow us to manipulate the streams independently before merging them. The order determines the layout: the first label appears on the left, and the second on the right.

Downscaling MP4 Video Using Nearest Neighbor Algorithm with FFmpeg discusses alternative scaling algorithms. While scale=-1:360 uses bicubic interpolation by default, which is good for general video, you might prefer scale2ref or specific flags if you need pixel-perfect sharpness for text-heavy thumbnails, though bicubic is usually sufficient for natural imagery.

Customizing Dimensions and Output

You can adjust the target height depending on your needs. For high-resolution displays, try 720 or 1080 pixels. Remember that increasing the height increases the file size and processing time linearly. If you are generating many thumbnails, consider using a lower height like 200 pixels for speed.

Additionally, you can control the background color. In the pad filter, the last argument specifies the fill color. Changing black to white or a hex code like #FF0000 allows you to match your brand identity. This is particularly useful if the portrait video has transparent areas or if you want the composite image to stand out against a white webpage background.

Automating the Process

For production environments, you likely need to process multiple pairs of videos. You can wrap this command in a bash script or a Python loop. Ensure that your input filenames correspond correctly to the indices 0:v and 1:v. If you have a list of portrait videos and a separate list of landscape videos, you may need to synchronize them by name or index before feeding them into the FFmpeg command. Always verify the output image visually to ensure the framing captures the key action in both clips.

Frequently Asked Questions

Why does my hstack command fail with "inputs must be of same size"?

This error occurs because the hstack filter strictly requires all input streams to have the exact same height. You must use the scale filter to force both portrait and landscape videos to a common pixel height before attempting to stack them horizontally.

How can I add padding to the portrait video instead of the landscape?

To pad the portrait video, calculate the target width based on the landscape aspect ratio (16:9). Use the pad filter with width=iw*16/9 (if starting from landscape) or a fixed width value, and center it using x=(ow-iw)/2. This ensures the portrait content remains centered within the expanded canvas.

Can I stack videos vertically instead of horizontally?

Yes, replace the hstack filter with vstack. This will place the portrait video on top of the landscape video. Note that you will need to ensure both inputs have the same width, not height, for vertical stacking to work correctly.

What is the best resolution for social media thumbnails?

For platforms like Instagram or TikTok, a height of 360 to 720 pixels is often sufficient. For YouTube or desktop websites, consider 720 or 1080 pixels. Always test the output on the actual device to ensure readability and visual appeal.

How do I handle videos with different frame rates?

FFmpeg handles different frame rates gracefully during filtering. However, for consistent playback if you were converting this to a video, you should use the setpts filter to synchronize timestamps. For static image extraction, frame rate differences do not affect the final composite image quality.

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