brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -vf transpose=1 turns a sideways phone video upright

Ffmpeg
~/tips/tip-ffmpeg-transpose-rotate

ffmpeg -i sideways.mp4 -vf transpose=1 -c:a copy upright.mp4

Rotates the picture of a video by 90 degrees, clockwise or counterclockwise.

A phone video that plays sideways on the TV is annoying. The transpose filter turns the actual pixels, so it looks right in every player.

ffmpeg -i sideways.mp4 -vf transpose=1 -c:a copy upright.mp4

transpose=1 rotates 90 degrees clockwise and transpose=2 90 degrees counterclockwise. For 180 degrees, chain two of them: -vf transpose=1,transpose=1. A 1280×720 file comes out as 720×1280, so width and height swap as you’d expect.

Before you re-encode anything, check whether the file just has a rotation flag. Phones often store the picture as it was shot and add a note saying “show this rotated”. ffprobe shows it as a display matrix or rotation in the side data. Players that ignore that note show the video sideways. In that case, recent ffmpeg versions apply the rotation by themselves when they re-encode, so a plain re-encode may already fix it, and adding transpose on top turns it too far.

So I’d look first with ffprobe -v error -show_streams sideways.mp4 | grep -i rotat. If that prints nothing, transpose it is. The audio is copied, but the picture always gets re-encoded with a filter.

Further reading: FFmpeg filters documentation, ffprobe documentation

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link