Rotate MP4 video using ffmpeg

ffmpegvideo

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%

Best Answer

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?

Related Question