ffmpeg fails at jpeg EXIF orientation (test included)
|Reported by:||Johnny||Owned by:|
|Blocking:||Reproduced by developer:||no|
|Analyzed by developer:||no|
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-orientation-examples
- 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 viewer).
What needs fixing:
- 4 years ago (2014), ffmpeg added EXIF metadata reading: http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=bb4e1b4cf910af0de2bc884c75544603c40010cc
- 3 years ago (2015), ffmpeg added video autorotation: http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=f5b26fbc2f564831b337f1de9faaaf6753a03871
- 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
orientationflag, 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.
Change History (9)
follow-ups: 2 3 comment:1 by , 4 years ago
|Keywords:||exif jpg jpeg orientation removed|
|Priority:||important → normal|
|Status:||new → closed|
comment:6 by , 4 years ago
|Component:||undetermined → avcodec|
|Keywords:||mjpeg rotate added|
|Priority:||normal → wish|
|Status:||closed → reopened|
|Type:||defect → enhancement|
|Version:||unspecified → git-master|