Opened 13 years ago

Closed 9 years ago

#515 closed defect (fixed)

Problem in video rotation in FFMPEG for IPhone video

Reported by: Gagan Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords: mov
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

I am trying to to compress IPhone recorded .mov file in to .mp4. If i record video in portrait mode in IPhone then after compression output video rotate automatically by 90 degree. I saw there are many patches given by some guys but they are just for extracting orientation information not for rotating output video.

I am working on 0.8.4 version. Please let me know are you planning to fix this issue in coming build version or is there any other way to handle this issue ?

Change History (12)

comment:1 by Carl Eugen Hoyos, 13 years ago

Priority: importantnormal

Please add missing information like command line (as short as possible, using no external libraries) and complete, uncut output to make this a valid ticket.
You can use the file sample-in-issue-505.mov from ticket #505

comment:2 by Gagan, 13 years ago

I am not working from command line tool. I integrated ffmpeg libraries in my IPhone project and doing compression through code. Can you tell me how can we rotate video through code ? I apply the fixes or patches given by few users in "mov_read_tkhd" method in mov.c file (see below). But i guess they are to just extract orientation information in auxMatrix, but i want to rotate file by 90 degree.

for (i = 0; i < 3; i++) {

st->auxMatrix[i][0] = display_matrix[i][0] = avio_rb32(pb); 16.16 fixed point
st->auxMatrix[i][1] = display_matrix[i][1] = avio_rb32(pb);
16.16 fixed point
avio_rb32(pb); 2.30 fixed point (not used)

}


comment:3 by Carl Eugen Hoyos, 12 years ago

Keywords: mov added
Version: 0.8.4git-master

comment:4 by Carl Eugen Hoyos, 12 years ago

Component: avformatFFmpeg
Reproduced by developer: set
Status: newopen

out.avi is not rotated correctly. ffmpeg should honor the "rotate" metadata set by the mov demuxer and automatically insert the transpose filter.

$ ffmpeg -i sample-in-issue-505.mov -an out.avi
ffmpeg version N-46747-ga1b5c96 Copyright (c) 2000-2012 the FFmpeg developers
  built on Nov 15 2012 09:06:47 with gcc 4.7 (SUSE Linux)
  configuration:
  libavutil      52.  6.100 / 52.  6.100
  libavcodec     54. 72.100 / 54. 72.100
  libavformat    54. 36.100 / 54. 36.100
  libavdevice    54.  3.100 / 54.  3.100
  libavfilter     3. 23.100 /  3. 23.100
  libswscale      2.  1.102 /  2.  1.102
  libswresample   0. 16.100 /  0. 16.100
  libpostproc    52.  1.100 / 52.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample-in-issue-505.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 0
    compatible_brands: qt
    creation_time   : 2011-09-25 10:10:07
    encoder         : 4.3.5
    encoder-deu     : 4.3.5
    date            : 2011-09-25T12:09:54+0200
    date-deu        : 2011-09-25T12:09:54+0200
  Duration: 00:00:03.49, start: 0.000000, bitrate: 794 kb/s
    Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, s16, 63 kb/s
    Metadata:
      creation_time   : 2011-09-25 10:10:07
      handler_name    : Core Media Data Handler
    Stream #0:1(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x272, 712 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc
    Metadata:
      rotate          : 90
      creation_time   : 2011-09-25 10:10:07
      handler_name    : Core Media Data Handler
Output #0, avi, to 'out.avi':
  Metadata:
    major_brand     : qt
    minor_version   : 0
    compatible_brands: qt
    date-deu        : 2011-09-25T12:09:54+0200
    ICRD            : 2011-09-25T12:09:54+0200
    encoder-deu     : 4.3.5
    ISFT            : Lavf54.36.100
    Stream #0:0(und): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 480x272, q=2-31, 200 kb/s, 30 tbn, 30 tbc
    Metadata:
      rotate          : 90
      creation_time   : 2011-09-25 10:10:07
      handler_name    : Core Media Data Handler
Stream mapping:
  Stream #0:1 -> #0:0 (h264 -> mpeg4)
Press [q] to stop, [?] for help
frame=  106 fps=0.0 q=7.4 Lsize=     146kB time=00:00:03.53 bitrate= 338.0kbits/s
video:138kB audio:0kB subtitle:0 global headers:0kB muxing overhead 5.898211%

comment:5 by Kai Hendry, 12 years ago

I'm suffering from this rotation issue WRT Iphone5 videos I take. They are upside down once I've transcoded them. If I do rotate them (which I should not have to do!), then they appear upside down on Safari.

https://github.com/kaihendry/recordmydesktop2.0/issues/1
http://ffmpeg.org/pipermail/ffmpeg-user/2012-November/011227.html
http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/154159

Here is the original movie from my iphone that exhibits the problem with the very latest ffmpeg: http://r2d2.webconverger.org/2012-11-14/silent-boot.mov

I'm *guessing* there is some rotation metadata like what a JPEG stores which some players don't respect?

comment:6 by DonMoir, 12 years ago

The original silent-boot.mov has a metadata rotate value of 180 degrees. It is up to any player or converter to take this into account. This rotation value orients the video to normal viewing. Sadly, some players and converters do not take this into account.

It would even be worse if you manually rotated it and the metadata rotate value was left in place in the result output video. Now it would be upside down in programs that do respect the metadata rotate value.

comment:7 by llogan, 10 years ago

Resolution: wontfix
Status: openclosed

By default all stream metadata, including rotation, are copied to the output. This can cause surprising results because:

  • Some users are unaware that stream rotation metadata exists and that their player is using it to orient the video (the ffmpeg console output will display this metadata).
  • Users will attempt to physically rotate the video with a filter, but the stream rotation metadata will be preserved by default (if supported by the output) unless the user modifies it appropriately.
  • Some players ignore the stream rotation metadata and others do not.

In my opinion users are responsible for removing or modifying the metadata with -metadata:s:v rotate="" or -metadata:s:v rotate=0 or whatever value they need if they decide to physically rotate the video.

Alternatively, maybe someone could add an option to a filter to use the metadata to provide the rotation value while automatically removing or modifying the rotation metadata. Perhaps something like -vf rotate=auto=1 (and in this case automatically add bilinear=0 for angles divisible by 90).

comment:8 by Carl Eugen Hoyos, 10 years ago

Resolution: wontfix
Status: closedreopened

Imo, this ticket is far too important to be closed.

comment:9 by Clément Bœsch, 10 years ago

We could probably copy the behavior of ImageMagick, with an option such as -auto-orient in ffmpeg tool, which would use the rotate metadata to insert the filter (as with ffplay), and drop it from the output metadata.

comment:10 by Carl Eugen Hoyos, 10 years ago

Shouldn't -auto-orient be the default?

comment:11 by Kai Hendry, 10 years ago

As a workaround, I've clumsily implemented a shell script to autorotate videos I take from an iPhone6 https://github.com/kaihendry/recordmydesktop2.0/blob/master/htmlvideo#L44 using ffprobe.

comment:12 by llogan, 9 years ago

Resolution: fixed
Status: reopenedclosed

This has been implemented in ffplay for some time. For ffmpeg it is now default behavior (as of f5b26fbc2f564831b337f1de9faaaf6753a03871) to automatically rotate video based on the metadata. It is enabled by default, but can be disabled with -noautorotate. The rotate metadata will not be copied so you won't have to use -metadata:s:v rotate="" to strip it.

Note: See TracTickets for help on using tickets.