FFmpeg concat rejects mixed video sizes? Fit the clips without stretching them
A landscape clip and a portrait clip both played on their own. FFmpeg rejected them at the join. Forcing both into 960×540 got the frame sizes to agree, but it also turned the circle in the portrait clip into an ellipse. The fix was to scale each clip to fit, then pad it to the same frame size. The

two video-only clips in this lab had square pixels. The worked command below joins them without cropping the portrait clip. It uses Bash and an FFmpeg build that includes the libx264 encoder. Run this for each input: for clip in wide.mp4 tall.mp4; do printf '%s\n' "$clip" ffprobe -v error -select_streams v:0 \ -show_entries stream=width,height,sample_aspect_ratio,avg_frame_rate \ -of compact=p=0 "$clip" done The first clip was 640×360 at 24 fps.
The second was 360×640 at 30 fps. Both reported a sample aspect ratio (SAR) of 1:1, meaning square pixels. Here are actual frames decoded from the two input files: The concat filter needs matching frame dimensions. With no normalization, it reported 360×640 versus 640×360 and the command returned nonzero.
Trying the concat demuxer with -c copy would not resize anything: stream copy skips the pixel transformations needed here. Pick the destination shape first. A 960×540 landscape delivery means the portrait clip will have bars on the sides. If the project is a vertical video, choose a vertical canvas and expect bars above and below the landscape clip instead.
Directly scaling to 960×540 and setting SAR to 1 makes the portrait frame fill every pixel. The test circle measured 429×135 pixels in that decoded frame. The distortion is obvious here. With faces or product shots, a smaller change in shape can escape a quick look.
Use the same fit-and-pad chain on both inputs. The first filter respects the source proportions and permits small rounding for even dimensions. The second fills the rest of the canvas with black. Then the chain sets square pixels, targets 30 fps, and restarts each clip’s timestamps at zero.
fit='scale=960:540:force_original_aspect_ratio=decrease:force_divisible_by=2' frame='pad=960:540:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,setpts=PTS-STARTPTS' ffmpeg -i wide.mp4 -i tall.mp4 \ -filter_complex "[0:v:0]$fit,$frame[a];[1:v:0]$fit,$frame[b];[a][b]concat=n=2:v=1:a=0[out]" \ -map '[out]' -r 30 -c:v libx264 -pix_fmt yuv420p fitted.mp4 In the graph, [a] and [b] are the two normalized video inputs. Output -r 30 asks FFmpeg for a fixed 30 fps cadence. In this lab that explicit output request gave a measured 2.000-second container with 60 frames. This command produces video without audio.
If the inputs have audio you need to keep, plan separate video and audio streams and specify what should happen when one clip has no audio. If the probe reports non-square pixels, normalize their display geometry first; blindly overwriting SAR can squeeze that footage. The command here was tested on square-pixel inputs only. The portrait frame at 1.25 seconds has the bars we expected, and its test circle measures 135×135 pixels.
Nothing near the left or right of the original portrait frame had to be cut off. At 0.25 seconds, the landscape frame fills the same 960×540 canvas. Its circle measures 240×241 pixels, within the small difference expected from scaling and encoding. Looking at both times also checks clip order.
Finally, probe the result instead of trusting the filename. The FFmpeg 7.1.5 lab reported 960×540, SAR 1:1, 30 fps, 60 frames and 2.000 seconds. A correct header cannot tell you whether someone stretched the picture; keep the two frame checks as well. ffprobe -v error -select_streams v:0 \ -show_entries stream=width,height,sample_aspect_ratio,avg_frame_rate,nb_frames:format=duration \ -of compact=p=0 fitted.mp4 Sources: FFmpeg documentation for concat, scale, pad, and ffprobe.
Visuals: original diagrams and decoded frames from a local FFmpeg 7.1.5 run using synthetic subjects. Disclosure: This article was prepared using a fully autonomous AI workflow. The examples were run locally and both resulting frame geometry and stream metadata were checked.
Key Takeaways
- •The worked command below joins them without cropping the portrait clip.
- •This story was reported by Dev.to, covering developments in the dev space.
- •AI advancements continue to reshape industries — read the full article on Dev.to for complete coverage.
📖 Continue reading the full article:
Read Full Article on Dev.to →


