How to Rotate Videos from iPhone in Linux
Posted on In LinuxiPhone is nice to take videos. However, one headache is the video may be rotated by 90 degree if you play it with non-Apple software such as MPlayer on Linux or Windows. This tutorial will introduce how to rotate the video taken from iPhone or other sources on Linux by 90 degree.
The tool we choose to use is ffmpeg
which can rotate video with video filters.
ffmpeg
supports several “transpositions”:
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
To rotate 90 clockwise, we will choose “1” like:
ffmpeg -i in.mov -vf "transpose=1" -strict -2 out.mov
However, this can work but still has problems: 1) the video aspects are wrong. 2) the quality is relatively low.
To solve the problems, we can do it by one single shot: setting the aspect during rotating the video by specifying -s
to ffmpeg
. Now, the problem is how to get the video aspect. MPlayer can help here.
mplayer -frames 0 -identify ./in.mov 2>/dev/null | grep ^VIDEO
It will print out the aspect of the video like:
VIDEO: [H264] 1920x1080 24bpp 29.970 fps 21551.4 kbps (2630.8 kbyte/s)
After it is rotated, it should be “1080×1920”. It may be quite large and usually can be reduced to some smaller one like “540×960” respectively if you like.
The ffmpeg
command will be like:
ffmpeg -i in.mov -vf "transpose=1" -s 540x960 -strict -2 out.mov
Bonus: MPlayer can also rotate the video during playing:
mplayer -vf-add rotate=1 in.mov
It has the same problem as ffmpeg
: it does not know the new aspect and you will need to set it manually. Making the video fullscreen and then turn it back will usually set the correct video aspect.
Eric, thanks for the post. Just what I was looking for :D