immich icon indicating copy to clipboard operation
immich copied to clipboard

[BUG] raw NEF file not rendering after upload

Open ClumsyAdmin opened this issue 2 years ago • 2 comments
trafficstars

The bug

If you upload the following raw photo it will not properly generate thumbnails for it, it will just be shown as blurry https://s3.amazonaws.com/Sample_NEFs/blackbird.nef.zip

The image above is just an example image I found online but this same issue happens with my entire raw library.

The OS that Immich Server is running on

Debian 11

Version of Immich Server

v1.65.0

Version of Immich Mobile App

v1.65.0

Platform with the issue

  • [X] Server
  • [ ] Web
  • [ ] Mobile

Your docker-compose.yml content

version: "3.8"

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:release
    entrypoint: [ "/bin/sh", "./start-server.sh" ]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - redis
      - database
      - typesense
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:release
    entrypoint: [ "/bin/sh", "./start-microservices.sh" ]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - redis
      - database
      - typesense
    restart: always

  immich-machine-learning:
    container_name: immich_machine_learning
    image: ghcr.io/immich-app/immich-machine-learning:release
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - model-cache:/cache
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    restart: always

  immich-web:
    container_name: immich_web
    image: ghcr.io/immich-app/immich-web:release
    entrypoint: [ "/bin/sh", "./entrypoint.sh" ]
    env_file:
      - .env
    restart: always

  typesense:
    container_name: immich_typesense
    image: typesense/typesense:0.24.0
    environment:
      - TYPESENSE_API_KEY=${TYPESENSE_API_KEY}
      - TYPESENSE_DATA_DIR=/data
    logging:
      driver: none
    volumes:
      - tsdata:/data

  redis:
    container_name: immich_redis
    image: redis:6.2
    restart: always

  database:
    container_name: immich_postgres
    image: postgres:14
    env_file:
      - .env
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      PG_DATA: /var/lib/postgresql/data
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: always

  immich-proxy:
    container_name: immich_proxy
    image: ghcr.io/immich-app/immich-proxy:release
    environment:
      # Make sure these values get passed through from the env file
      - IMMICH_SERVER_URL
      - IMMICH_WEB_URL
    ports:
      - 2283:8080
    logging:
      driver: none
    depends_on:
      - immich-server
    restart: always

volumes:
  pgdata:
  model-cache:
  tsdata:

Your .env content

###################################################################################
# Database
###################################################################################

DB_HOSTNAME=immich_postgres
DB_USERNAME=
DB_PASSWORD=
DB_DATABASE_NAME=immich

# Optional Database settings:
# DB_PORT=5432

###################################################################################
# Redis
###################################################################################

REDIS_HOSTNAME=immich_redis

# Optional Redis settings:
# REDIS_PORT=6379
# REDIS_DBINDEX=0
# REDIS_PASSWORD=
# REDIS_SOCKET=

###################################################################################
# Upload File Config
###################################################################################

UPLOAD_LOCATION=/mnt/slab1/photos/immich/data/

###################################################################################
# Log message level - [simple|verbose]
###################################################################################

LOG_LEVEL=simple

###################################################################################
# JWT SECRET
###################################################################################

JWT_SECRET=

###################################################################################
# Reverse Geocoding
####################################################################################

# DISABLE_REVERSE_GEOCODING=false

# Reverse geocoding is done locally which has a small impact on memory usage
# This memory usage can be altered by changing the REVERSE_GEOCODING_PRECISION variable
# This ranges from 0-3 with 3 being the most precise
# 3 - Cities > 500 population: ~200MB RAM
# 2 - Cities > 1000 population: ~150MB RAM
# 1 - Cities > 5000 population: ~80MB RAM
# 0 - Cities > 15000 population: ~40MB RAM

REVERSE_GEOCODING_PRECISION=3

####################################################################################
# WEB - Optional
####################################################################################

# Custom message on the login page, should be written in HTML form.
# For example PUBLIC_LOGIN_PAGE_MESSAGE="This is a demo instance of Immich.<br><br>Email: <i>[email protected]</i><br>Password: <i>demo</i>"

#PUBLIC_LOGIN_PAGE_MESSAGE=
TYPESENSE_API_KEY=

Reproduction steps

1. Upload file
2. Generate missing (or all) thumbnails
3. Wait to finish, check image and it is blurry and not properly rendered.

Additional information

No response

ClumsyAdmin avatar Jul 01 '23 15:07 ClumsyAdmin

This is a known issue with NEF file get properly render. Do you see a duplicated reported issue by chance?

alextran1502 avatar Jul 01 '23 16:07 alextran1502

This is a known issue with NEF file get properly render. Do you see a duplicated reported issue by chance?

No I checked before hand and there wasn't a single open issue with NEF in the title/body etc

ClumsyAdmin avatar Jul 01 '23 16:07 ClumsyAdmin

It's my first time looking around in the codebase, and I also can't test it locally (yet), but from testing on my own instance, I found out that there should be two types of thumbnail files in the thumb directory, right? A tiny 375x250px thumbnail in webp format that is used on the album view, and a large (in my case 2160x1440px) jpeg file that is shown when opening up the image.

If I upload a jpeg image, these two get properly created and sized accordingly, however if I upload nef image, the sizes are as follows:

webp thumbnail: 160x120px jpeg thumbnail: 160x120px

The webp version is already smaller (=blurrier) than what it should be, and the jpeg version is the same tiny size instead of 2160px width, so not only is the thumbnail in the overview blurry, the zoomed image definitely is.

Does the backend generate one from the other? Maybe the jpeg first and then the webp from that? That would explain the identical dimensions, at least. In that case, we'd need to look at what the resize function does when you feed it NEF files.

jannisbecker avatar Aug 06 '23 14:08 jannisbecker

That is correct. We generate the jpeg from the original and then the webp from the jpeg.

This looks like an issue with sharp generating the jpeg thumbnail from the original.

jrasm91 avatar Aug 06 '23 18:08 jrasm91

I can confirm the same issue with tiny NEF thumbs (160x120px) being generated after upload to v1.72.2

andreybavt avatar Aug 10 '23 08:08 andreybavt

I managed to reproduce locally, the easiest is to simply run:

const sharp = require('sharp');
sharp('test.nef').jpeg().resize(1400).toFile('resize.jpg')

Here's a reason why it doesn't work (sharp doesn't support NEF) https://github.com/lovell/sharp/issues/616

And here's where 160x120 is coming from: http://lclevy.free.fr/nef/

IFD#0 also contains a thumbnail image in uncompressed TIFF, size is 160x120.

So far it seems that the only option is to add node-libraw dependency to immich and call it instead of sharp. I'm looking at other ways to convert nef->jpg from node

andreybavt avatar Aug 11 '23 00:08 andreybavt

it seems that https://github.com/m0g/node-libraw isn't maintained. I wonder if it's just not easier to call python's rawpy for example from MediaRepository.resize

andreybavt avatar Aug 11 '23 01:08 andreybavt

So, I'm confused. I can see that vips is pretty happy to delegate this work to imagemagick.

~/abc # vips thumbnail blackbird.nef  out.jpg 100

(vips:57): VIPS-WARNING **: 21:08:23.806: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.807: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.807: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.807: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.807: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.807: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.807: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.808: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.809: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.809: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.809: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.809: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.809: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.809: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.809: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.810: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.810: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.810: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.810: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.810: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.810: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.810: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.810: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.811: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.812: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.812: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.812: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.819: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.819: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.819: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.819: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.820: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.820: Unknown field with tag 37398 (0x9216) encountered

(vips:57): VIPS-WARNING **: 21:08:23.820: Invalid TIFF directory; tags are not sorted in ascending order

(vips:57): VIPS-WARNING **: 21:08:23.820: Unknown field with tag 36867 (0x9003) encountered

(vips:57): VIPS-WARNING **: 21:08:23.820: Unknown field with tag 37398 (0x9216) encountered
~/abc # identify out.jpg 
out.jpg JPEG 100x66 100x66+0+0 8-bit sRGB 9149B 0.000u 0:00.001

The image produced is pretty bad though, I guess it's using the embedded preview.

image

A direct conversion with imagemagick is obviously fine.

~/abc # convert blackbird.nef -thumbnail 600x out.jpg

image

Seems like https://github.com/libvips/libvips/issues/255#issuecomment-88246805?

Maybe actually https://github.com/libvips/libvips/issues/3380 (which it looks like @mertalev found too!)

It's a shame they didn't actually add good support for nef detection. I wonder if there's more we can do aside from just disabling tiff entirely.

uhthomas avatar Aug 12 '23 21:08 uhthomas