Edit video rotation metadata in FFmpeg

I am recording a lot of short videos these days for my sound actions project. Sometimes the recordings end up being rotated, which is based on the orientation sensor (probably the gyroscope) of my mobile phone. This rotation is not part of the recorded video data, it is just information written into the header of the MPEG file. That also means that it is possible to change the rotation without recoding the file. It is possible to see the rotation by looking at the metadata of a file:

ffmpeg -i filename.mp4

Then you will see a lot of information about the file. A bit down in the list is information about the rotation:

Side data:
displaymatrix: rotation of -90.00 degrees

Fixing it is as simple as running this command on the file:

ffmpeg -i filename.mp4 -c copy -metadata:s:v:0 rotate=0 output.mp4

This will quickly copy the video data over to a new file and fix the metadata information.

Published by


Alexander Refsum Jensenius is a music researcher and research musician living in Oslo, Norway.