Rotate a video file 90 degrees using Ubuntu

39,735

Solution 1

by using VLC, you may rotate the video by going to Tools >> Preferences...

And select "All" for show settings. Then go to: Video >> Filters >> Rotate

After setting the degree you want, you can rotate by going to Tools > Effects and Filters > Video Effects > Geometry .. .

alt text

the one I've tested is mp4 but I believe that VLC can support 3gp too. hope this helps. :)

Solution 2

From the command-line, with ffmpeg:

ffmpeg -i input.3gp -filter:v transpose=1 \
-c:v libx264 -preset veryfast -crf 22 \
-c:a copy \
-metadata:s:v rotate="" \
output.3gp
  • transpose=1 will rotate the video 90 degrees clockwise; to rotate anti-clockwise, use transpose=2. See the transpose documentation for a bit more information.

  • -metadata:s:v rotate="" will strip any existing video stream rotation metadata; otherwise ffmpeg will copy it which may cause your player to apply additional unwanted rotation.

  • For information on the video encoding settings here, see this H.264 encoding guide and the AAC encoding guide if you want to re-encode the audio instead of stream copying.

Solution 3

There have been some changes to libav since the time that this question was originally answered. In an attempt to keep this current and useful I'll provide the followng:

You can accomplish this with recent versions of ffmpeg and avconv by using the transpose video filter.

avconv -i inputfile -vf transpose=clock outputfile

for clockwise rotation.

in ffmpeg the syntax is the same.

ffmpeg -i inputfile -vf transpose=clock outputfile

where inputfile is your supported input video file and outputfile is your desired output file.

For counter clockwise rotation replace clock with cclock

Here's an excerpt from the documentation:

‘cclock_flip’

    Rotate by 90 degrees counterclockwise and vertically flip. (default)
‘clock’

    Rotate by 90 degrees clockwise.
‘cclock’

    Rotate by 90 degrees counterclockwise.
‘clock_flip’

    Rotate by 90 degrees clockwise and vertically flip. 

Sources:

https://libav.org/avconv.html#transpose

https://ffmpeg.org/ffmpeg-filters.html#transpose-1

Testing on Ubuntu 14.04.5 LTS, Ubuntu 16.04, Ubuntu 18.04

Solution 4

Avidemux should be able to do this.

Do Video->Filters->Rotate(x degrees)->Close then File->Save->Save Video

Solution 5

I don't know exactly what the difference is, but the top answer ffmpeg command takes a very long time to run on my computer in order to rotate a video.

This ffmpeg command on the other hand took only about 7 seconds to rotate a 2gb video file:

ffmpeg -i input-video.mov -metadata:s:v rotate="-90" -codec copy output-video.mov
Share:
39,735

Related videos on Youtube

justinhj
Author by

justinhj

Updated on September 17, 2022

Comments

  • justinhj
    justinhj almost 2 years

    I want to use Ubuntu and preferably standard packages such as ffmpeg to rotate a .3gp video file by 90 degrees in any direction. Preferably a command line or Python script.

    How can I do that?

  • justinhj
    justinhj about 14 years
    i can view the video rotated, but how do you make the change persist
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' about 9 years
    Welcome to Super User.  (1) While some background information in your answer may be helpful, it’s best to focus on your solution to the problem.  I’ve edited your answer to illustrate; feel free to edit it further if you believe that I changed too much.  (2) The display order of answers may vary; it’s better to identify other answer(s) explicitly rather than saying “above”.  (2½) I hope you presented your avconv command lines in their entirety, and not just the differences from the ffmpeg command.  Your answer should be self-sufficient; the other answer might go away.  (3) Good luck!
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' about 9 years
    Also, I assume that when you say “result was satisfactory” you mean that your “result” file looked as good as the original file.  You might want to (edit your message to) say so explicitly.  (Such information — i.e., whether you lost video quality visible to the eye — is important to your answer, and shouldn’t be hidden away in a comment.)  Also, I betcha you could leave out the quotes and say just -filter:v transpose=1 ….
  • mbernasocchi
    mbernasocchi over 7 years
  • J.W.F.
    J.W.F. about 7 years
    This better answers the question as it explains how to do it from the command line with ffmpeg, as specified in the original question. I think this answer should be marked as correct. As of May 2017 on Fedora 25, this still works, albeit a deprecation message for the MP4 codec.
  • Amil Waduwawara
    Amil Waduwawara almost 5 years
    Thanks for the minimal parameters. ffmpeg worked for me (didn't try avconv)
  • Mariano Ruiz
    Mariano Ruiz over 4 years
    Excellent! yes many posts about ffmpef includes a lot of unnecessary arguments, thanks!
  • Elder Geek
    Elder Geek over 4 years
    @MarianoRuiz I'm glad it helped you. ffmpeg is always in development so over time things change. It's not surprising that easier methods exist than some of the older answers. Cheers!
  • Denis Trofimov
    Denis Trofimov over 2 years
    I like that no decoding/encoding is needed, done in a flash! Works great with mp4, m4v too!