stash
stash copied to clipboard
Extend orientation / rotation support for files on load
Potentially fixes #4555, #4738, #3479 by adding support to parse out rotation
frame side_data from FFMPEG / ffprobe
I manually tested this with a small set of reproducing JPEG images, but have not yet had the chance to try out other image types.
Thanks to @onlyhooops for their repro images, and to @zhyu for calling out the ffprobe tooling.
Thank you for fixing this issue, it makes the project even more perfect.🎉
JFYI, this repo contains example images with all possible EXIF orientation values.
Thanks for your submission and apologies for the delay in looking into this.
I will further investigate this, but right now this change has a significant performance impact on scanning regular video files. The probJSON.PacketsAndFrames
ends up with a length of over 10,000 entries. The -show_entries
argument seems to be the cause.
Closing in favour of #5189.
~~I found that in the latest version (v0.26.2-93-g306ba63a), under the same file, stash is unable to build thumbnails with the correct aspect ratio again. http://up.ccp.ovh/files/xgPx9/Snipaste_2024-09-03_18-51-36.png~~
Through testing, I discovered that the issue was caused by the discrepancy between the orientation of the self-generated thumbnails and the actual orientation of my photo files. After processing the photo files with the following code, everything is now normal.
`import piexif from PIL import Image
def rotate_by_orientation(filename): img = Image.open(filename) if 'exif' in img.info: exif_dict = piexif.load(img.info['exif']) if piexif.ImageIFD.Orientation in exif_dict['0th']: orientation = exif_dict['0th'].pop(piexif.ImageIFD.Orientation) exif_bytes = piexif.dump(exif_dict) if orientation == 2: img = img.transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 3: img = img.rotate(180) elif orientation == 4: img = img.rotate(180).transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 5: img = img.rotate(-90, expand=True).transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 6: img = img.rotate(-90, expand=True) elif orientation == 7: img = img.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 8: img = img.rotate(90, expand=True) img.save(filename, exif=exif_bytes) print('over')
if name == 'main': rotate_by_orientation('1.jpg') `