All posts
Rotate video via CLI
ffmpeg transpose rotates 90°; hflip,vflip is 180°.
Open online converterPackages to install
Only ffmpeg is required. Use libx264 for MP4 and libvpx-vp9 for WebM.
ffmpeg
sudo apt-get update
sudo apt-get install -y ffmpegHow to run the command
Clockwise 90° is transpose=1, counterclockwise 90° or clockwise 270° is transpose=2, 180° is hflip,vflip. Example: ffmpeg -i input.mp4 -vf "transpose=1,scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k output.mp4. Even dimensions keep yuv420p happy.
ffmpeg -y -i input.mp4 -vf "transpose=1,scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4Dockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t rotate-video .
docker run --rm -v "$PWD:/work" -w /work rotate-video \
ffmpeg -y -i input.mp4 -vf "transpose=1,scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4Example commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
ffmpeg -y -i input.mp4 -vf "transpose=1,scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4ffmpeg -y -i input.mp4 -vf "transpose=2,scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4