immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
51.43k stars 2.72k forks source link

Transcoding failing for videos from Samsung S23 Ultra #12780

Closed ryanwinter closed 1 month ago

ryanwinter commented 1 month ago

The bug

Transcoding is failing for many videos in my library (around 4000).

It appears that the video files is missing some Matrix coefficients needed by the x265 encoder.

The OS that Immich Server is running on

Ubuntu

Version of Immich Server

v1.115.0

Version of Immich Mobile App

v1.115.0

Platform with the issue

Your docker-compose.yml content

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:release
    restart: unless-stopped
    volumes:
      - /mnt/truenas_immich:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    environment:
      DB_PASSWORD: ${DB_PASSWORD}
      DB_USERNAME: ${DB_USERNAME}
      DB_DATABASE_NAME: ${DB_DATABASE_NAME}
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    labels:
      - "com.centurylinklabs.watchtower.enable=false"       
    healthcheck:
      disable: false

  immich-machine-learning:
    container_name: immich_machine_learning
    image: ghcr.io/immich-app/immich-machine-learning:release
    restart: unless-stopped
    volumes:
      - /volumes_tmp/immich/model-cache:/cache
    labels:
      - "com.centurylinklabs.watchtower.enable=false"       
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:2d1463258f2764328496376f5d965f20c6a67f66ea2b06dc42af351f75248792
    restart: unless-stopped
    volumes:
      - /volumes_tmp/immich/redis:/data
    labels:
      - "com.centurylinklabs.watchtower.enable=false"       
    healthcheck:
      test: redis-cli ping || exit 1

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    volumes:
      - postgres:/var/lib/postgresql/data
    labels:
      - "com.centurylinklabs.watchtower.enable=false"   
    healthcheck:
      test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1
      interval: 5m
      start_interval: 30s
      start_period: 5m
    command: ["postgres", "-c", "shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"]

volumes:
  postgres:

Your .env content

DB_USERNAME=xxx
DB_DATABASE_NAME=xxx
DB_PASSWORD=xxx

Reproduction steps

  1. Upload file from the my Samsung S23 Ultra
  2. Setup transcoding to hvec/aac
  3. Observe failure to create video thumbnail

Relevant log output

[Nest] 7  - 09/18/2024, 9:50:34 PM     LOG [Microservices:MediaService] Started encoding video ee37fb27-d9e6-42cb-a12f-d27611102032 {"inputOptions":[],"outputOptions":["-c:v hevc","-c:a copy","-movflags faststart","-fps_mode passthrough","-map 0:0","-strict unofficial","-map 0:1","-tag:v hvc1","-v verbose","-vf scale=480:-2,format=yuv420p","-preset superfast","-crf 30"],"twoPass":false}
[Nest] 7  - 09/18/2024, 9:50:34 PM   ERROR [Microservices:MediaRepository] ffmpeg version 6.0.1-Jellyfin Copyright (c) 2000-2023 the FFmpeg developers
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
[vost#0:0 @ 0x31f04172b80] Matched encoder 'libx265' for codec 'hevc'.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264 @ 0x31f04152580] Reinit context to 1088x1920, pix_fmt: yuv420p
[Parsed_scale_0 @ 0x31f04161680] w:480 h:-2 flags:'' interl:0
[graph 0 input from stream 0:0 @ 0x31f04120980] w:1080 h:1920 pixfmt:yuv420p tb:1/1000000 fr:30/1 sar:0/1
[Parsed_scale_0 @ 0x31f04161680] w:1080 h:1920 fmt:yuv420p sar:0/1 -> w:480 h:854 fmt:yuv420p sar:0/1 flags:0x00000004
x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 12.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
x265 [error]: Matrix Coefficients must be unknown, bt709, fcc, bt470bg, smpte170m, smpte240m, gbr, ycgco, bt2020nc, bt2020c, smpte-st-2085, chroma-nc, chroma-c or ictcp
    Last message repeated 3 times
[libx265 @ 0x31f04151180] Cannot open libx265 encoder.
[vost#0:0/libx265 @ 0x31f04172b80] Error initializing output stream: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Additional information

No response

alextran1502 commented 1 month ago

Hello, can you provide the settings of your video transcoding setup? Also, if you can provide a sample video so we can help reproduce, that would be helpful

ryanwinter commented 1 month ago

Hello, can you provide the settings of your video transcoding setup? Also, if you can provide a sample video so we can help reproduce, that would be helpful

Hey Alex,

These are my current settings: CRF: 30 Preset: superfast Codec: hvec / aac Target resolution: 480p Max bitrate: 0 Tone mapping: Hable Two-pass: off HW accel: off

You can see the output settings in the log above, but here it is in an easier to consume format :)

{
  "outputOptions": [
    "-c:v hevc",
    "-c:a copy",
    "-movflags faststart",
    "-fps_mode passthrough",
    "-map 0:0",
    "-strict unofficial",
    "-map 0:1",
    "-tag:v hvc1",
    "-v verbose",
    "-vf scale=480:-2,format=yuv420p",
    "-preset superfast",
    "-crf 30"
  ],
  "twoPass": false
}

Let me see if I can find a sample video that doesnt contain any person information. Maybe I can just try recording some new videos. I'll try and attach something tomorrow.,

ryanwinter commented 1 month ago

Something I noticed, is when I do an ffprobe --show_frames I get the following:

color_range=tv
color_space=reserved
color_primaries=reserved
color_transfer=smpte170m

I assumed reserved is not expected here? If I force the output color space with -colorspace smpte170m or -colorspace unknown at the ffmpeg command line, then it completes as expected.

ryanwinter commented 1 month ago

Just update that I'm still looking into this. All new videos are encoding successfully, so now I'm wondering where the failing videos came from. Its possible they were an output from some editing program.

alextran1502 commented 1 month ago

I am closing the issue, feel free to reopen when we find the reproducible steps