To rotate a video using FFmpeg, you can use the transpose
filter or the rotate
filter. Here are examples of both methods:
Using the transpose
filter:
ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output.mp4
In this example, input.mp4
is the horizontal screen video file, and output.mp4
is the resulting vertical screen video file.
The transpose
filter with a value of 1
is used to rotate the video 90 degrees clockwise, effectively converting it from horizontal to vertical orientation. The -c:a copy
option is used to copy the audio stream without re-encoding.
You can adjust the transpose value based on your specific requirements. Here are the available transpose values:
0
: Rotate 90 degrees counterclockwise and flip vertically (default).1
: Rotate 90 degrees clockwise.2
: Rotate 90 degrees counterclockwise.3
: Rotate 90 degrees clockwise and flip vertically.
Using the rotate
filter:
ffmpeg -i input.mp4 -vf "rotate=90*PI/180" -c:a copy output.mp4
In this example, input.mp4
is the input video file, and output.mp4
is the resulting rotated video file. The rotate
filter is used with an angle specified in radians. In this case, 90*PI/180
rotates the video 90 degrees clockwise. You can adjust the angle to rotate the video in different directions.
Both methods preserve the original audio stream without re-encoding using the -c:a copy
option.
Make sure you have FFmpeg installed on your system and accessible in the command line before running the command.