Rotate MP4 video using ffmpeg

7,736

You're not using the "real" ffmpeg from FFmpeg, but a broken program called ffmpeg from Libav.

Please download a recent ffmpeg version and try again.

See also: Who can tell me the difference and relation between ffmpeg, libav, and avconv?

Share:
7,736

Related videos on Youtube

user300863
Author by

user300863

Updated on September 18, 2022

Comments

  • user300863
    user300863 almost 2 years

    I have a webserver running ubuntu that accepts videos from an iPhone app. Obviously this wasn't playing on the Android version of the app as the video was a MOV file. I was easily able to convert the file to MP4 using ffmpeg:

    ffmpeg -i <input.mov> -vcodec copy -acodec copy <output.mp4>
    

    This allowed the videos to play in the Android version of the app, however they lost their rotation and played sideways on both iOS and Android.

    Now I'm trying to use ffmpeg to rotate the video so that it plays correctly using:

    ffmpeg -i <input.mp4> -vf "transpose=1" <output.mp4>
    

    but the output video is not rotated. I've tried various ways of rotating using ffmpeg but none have worked. These methods include:

    ffmpeg -i <input.mp4> -vcodec copy -acodec copy -vf "transpose=1" <output.mp4>
    ffmpeg -i <input.mp4> -metadata:s:v:0 rotate=90 <output.mp4>
    

    and various combinations of the commands, however there is never any change in the orientation of the video.

    I find it odd that the -vf doesn't work because after the upload, the server generates a thumbnail using:

    ffmpeg -y -itsoffset -1 -i <input.mp4> -vcodec mjpeg -vframes 1 -vf "transpose=1" -an -f rawvideo <output>
    

    which works perfectly and gives the thumbnail facing the correct direction.

    In any of the cases I'm not getting any errors so I'm not sure what's going wrong, the video just isn't rotated properly.

    As this needs to be done automatically it needs to be done from the command line.

    I just tried using:

    ffmpeg -i <input.mp4> -acodec copy -vcodec copy -vf "transpose=1" <output.mp4>
    

    with the result:

    ffmpeg version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers   built on Apr  2 2013 17:02:36 with gcc 4.6.3
    *** THIS PROGRAM IS DEPRECATED *** This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
    
    Seems stream 0 codec frame rate differs from container frame rate:
    1200.00 (1200/1) -> 29.97 (30000/1001) Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'media/test.mp4':   Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 2014-02-06 00:16:52
        date            : 2014-01-25T12:44:19-0800
        encoder         : Lavf53.21.1   Duration: 00:00:01.06, start: 0.000000, bitrate: 5391 kb/s
        Stream #0.0(und): Video: h264 (Main), yuv420p, 1280x720, 5489 kb/s, 29.95 fps, 29.97 tbr, 600 tbn, 1200 tbc
        Metadata:
          creation_time   : 2014-02-06 00:16:52
        Stream #0.1(und): Audio: aac, 44100 Hz, mono, s16, 57 kb/s
        Metadata:
          creation_time   : 2014-02-06 00:16:52 File 'media/temp.mp4' already exists. Overwrite ? [y/N] y Output #0, mp4, to 'media/temp.mp4':   Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 2014-02-06 00:16:52
        date            : 2014-01-25T12:44:19-0800
        encoder         : Lavf53.21.1
        Stream #0.0(und): Video: ![0][0][0] / 0x0021, yuv420p, 1280x720, q=2-31, 5489 kb/s, 600 tbn, 600 tbc
        Metadata:
          creation_time   : 2014-02-06 00:16:52
        Stream #0.1(und): Audio: aac, 44100 Hz, mono, 57 kb/s
        Metadata:
          creation_time   : 2014-02-06 00:16:52 Stream mapping:   Stream #0.0 -> #0.0   Stream #0.1 -> #0.1 Press ctrl-c to stop encoding frame=   31 fps=  0 q=-1.0 Lsize=     703kB time=1.00 bitrate=5739.6kbits/s     video:694kB audio:8kB global headers:0kB muxing overhead 0.267996%
    
    • Rajib
      Rajib over 10 years
      The first command to convert file from mov to mp4 should not rotate video in the first place. Please paste the exact command you use, and the output of that command (from first conversion only). Also, are you converting or playing back on Windows with ffdshow codec installed? Because I have placed problems with that package.
    • user300863
      user300863 over 10 years
      It's not that the command is rotating the video, it looks like it's actually just losing it's rotation metadata in the conversion process. I check before and after and the rotation goes from 90 to 0.
    • Rajib
      Rajib over 10 years
      What are you using to check rotation metadata?
    • user300863
      user300863 over 10 years
      I check the rotation with: 'exiftool <file> | grep Rotation'
    • Rajib
      Rajib over 10 years
      See this answer and also this
    • Elisa Cha Cha
      Elisa Cha Cha over 10 years
      You should always include the complete ffmpeg console outputs (or at least one of them).
    • user300863
      user300863 over 10 years
      Rajib: I've tried the solutions presented in both of those links with no success which is why I originally posted here. LordNeckbeard: I just added the results for one of my attempts that was not successful, but had no errors.
    • slhck
      slhck over 10 years
      Oh, you're not using the "real" ffmpeg from FFmpeg, but a broken program called ffmpeg from Libav (see Who can tell me the difference and relation between ffmpeg, libav, and avconv). Please download a recent ffmpeg version and try again. That's the reason we ask for the full output, since it's usually quite easy to debug what's the issue.
    • user300863
      user300863 over 10 years
      Thanks slhck, that seems to have been the problem and it's rotating now. However, there is now another issue for me to look into.
    • slhck
      slhck over 10 years
      Feel free to post a new question! Don't forget that you have to ping users with @slhck instead of just slhck in order for them to get a notification.