[FFmpeg-trac] #6945(undetermined:new): ffmpeg fails at jpeg EXIF orientation (test included)

FFmpeg trac at avcodec.org
Thu Jan 4 18:38:51 EET 2018

#6945: ffmpeg fails at jpeg EXIF orientation (test included)
             Reporter:  JohnnyX      |                     Type:  defect
               Status:  new          |                 Priority:  important
            Component:               |                  Version:
  undetermined                       |  unspecified
             Keywords:               |               Blocked By:
  exif,jpg,jpeg,orientation          |  Reproduced by developer:  0
             Blocking:               |
Analyzed by developer:  0            |
 Summary of the bug:

 If you try viewing these test images in any other image viewer, they'll
 all display them correctly (all in the same orientation). Ffmpeg on the
 other hand fails to display them correctly.

 This is a major issue when using ffmpeg-based players as an image viewer,
 because most images these days (from digital cameras and phones) use EXIF
 orientation to tell the viewer how to display the image.

 Trying to use ffmpeg as an image viewer currently leads to a sad
 experience where images are rotated and flipped into crazy angles, rather
 than being displayed correctly. ;-)

 How to reproduce:

 - Download EXIF orientation test images from this repository (it covers
 all available JPG orientations): https://github.com/recurser/exif-

 - Try viewing/converting the JPEG with ffmpeg:

 ffmpeg -i Landscape_2.jpg test.png

 - The result will be badly flipped/rotated.

 - All images are supposed to look identical (as they will in a correct

 What needs fixing:

 - 4 years ago (2014), ffmpeg added EXIF metadata reading:

 - 3 years ago (2015), ffmpeg added video autorotation:

 - According to discussions (https://trac.ffmpeg.org/ticket/4149 and
 https://trac.ffmpeg.org/ticket/515), ffmpeg's stance is that it should
 always autorotate/autoflip the input by default to respect display-
 orientation flags. So ffmpeg missing the "orientation fix" for JPEG is
 just an oversight.

 - So the fix would be: "If input format == jpeg/exif with `orientation`
 flag, apply the orientation filters to the output".

 There are 8 JPEG EXIF orientations. They represent various combinations of
 rotate + vflip + hflip. And all of the code for rotate/flip filters is
 already available in ffmpeg. Just look at the video autorotate code above.
 It seems to be very easy to add this JPEG fix by just looking at that
 commit and the EXIF commit.

 I don't know this codebase at all and would just screw it up if I attempt
 this fix. Hopefully someone here wants to fix ffmpeg's broken JPEG
 support. It's important these days, since most camera sensors capture
 pixels in a single orientation and then add an EXIF `orientation` tag to
 assign the display-orientation. By lacking that feature, ffmpeg currently
 fails badly at almost all JPEG input.

Ticket URL: <https://trac.ffmpeg.org/ticket/6945>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list