Table of Contents

ffprobe - Video - Rotate

To detect whether videos are recorded in portrait or landscape mode.

Video orientation detection

ffprobe -v error -select_streams v:0 -show_entries stream_tags=rotate -of csv=s=x:p=0 input.mp4

NOTE: On unrotated videos, the above command produces no output.


Getting Width, Height, Rotation

ffprobe -v error -select_streams v:0 -show_entries stream=width,height:stream_tags=rotate -of csv=p=0 input.mp4

returns:

1920,1080,270

NOTE: Even though the rotation here is 270, the width and height are still shown as if the orientation was portrait.

  • Due to the 270 rotation, in reality the actual input should be 1080×1920, and not 1920×1080.
    • But ffprobe reports the actual width x height; Width is displayed first, then height (no matter the order it is requested).

Using Grep

ffprobe somevideo.mp4 2>&1 | grep rotate

returns:

rotate          : 90

In a Bash Script

rotate=$(ffprobe -v error -select_streams v:0 -show_entries stream_tags=rotate -of csv=s=x:p=0 "${sourceFile}")
if [ "$rotate" != "" ]; then 
    echo "We need to rotate: $rotate"
fi