immich-app / immich

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

[BUG] AVI video cannot be played in browser, works in Android app, playback endpoint returns raw video instead of transcode #11094

Closed zdimension closed 1 month ago

zdimension commented 1 month ago

The bug

Uploaded an AVI file to Immich. File can be played in Android app. In browser, the mouseover shows the error icon: (gif below) chrome_uJyu9bKQyr After clicking, the HTML5 video loading spinner appears for a second then disappears, and the Immich loading spinner spins forever: (gif below) chrome_jdlJyaKw1G

This bug was also previously mentioned here.

All my other videos (MPEG, ...) work.

The OS that Immich Server is running on

Debian 11 x86_64

Version of Immich Server

v1.108.0

Version of Immich Mobile App

n/a

Platform with the issue

Your docker-compose.yml content

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    command: ['start.sh', 'immich']
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    extends:
      file: hwaccel.transcoding.yml
      service: nvenc
    command: ['start.sh', 'microservices']
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
    restart: always

  immich-machine-learning:
    container_name: immich_machine_learning
    # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
    # Example tag: ${IMMICH_VERSION:-release}-cuda
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}-cuda
    extends:
      file: hwaccel.ml.yml
      service: cuda
    volumes:
      - model-cache:/cache
    env_file:
      - .env
    restart: always

  redis:
    container_name: immich_redis
    image: registry.hub.docker.com/library/redis:6.2-alpine@sha256:84882e87b54734154586e5f8abd4dce69fe7311315e2fc6d67c29614c8de2672
    restart: always

  database:
    container_name: immich_postgres
    image: registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    volumes:
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    restart: always

volumes:
  model-cache:

Your .env content

# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables

# The location where your uploaded files are stored
UPLOAD_LOCATION=/storage/immich/library
# The location where your database files are stored
DB_DATA_LOCATION=/storage/immich/postgres

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=release

# Connection secret for postgres. You should change it to a random password
DB_PASSWORD=iQgqe2dZyNAyQpZ

# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=postgres
DB_DATABASE_NAME=immich

TZ=Europe/Paris

Reproduction steps

1. Upload AVI file
2. Try to play it in browser

Relevant log output

Nothing relevant I could find in logs, unfortunately. No errors when force-running transcoding, nor when playing.

Additional information

AVI info:

General
Complete name                            : 00969812.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 16.4 MiB
Duration                                 : 3 min 53 s
Overall bit rate                         : 587 kb/s
Writing application                      : MEncoder SVN-r29352(20090610-gcc4.3.3)
Writing library                          : MPlayer

Video
ID                                       : 0
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Baseline@L1.3
Format settings                          : 1 Ref Frames
Format settings, CABAC                   : No
Format settings, Reference frames        : 1 frame
Codec ID                                 : avc1
Duration                                 : 3 min 53 s
Bit rate                                 : 444 kb/s
Width                                    : 400 pixels
Height                                   : 300 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 25.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.148
Stream size                              : 12.4 MiB (76%)
Writing library                          : x264 core 67 r1163+17 7d945df
Encoding settings                        : cabac=0 / ref=1 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=6 / psy_rd=1.0:0.0 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / chroma_qp_offset=-2 / threads=6 / nr=0 / decimate=1 / mbaff=0 / bframes=0 / keyint=250 / keyint_min=25 / scenecut=40 / rc=abr / bitrate=444 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00

Audio
ID                                       : 1
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Format settings                          : Joint stereo / MS Stereo
Codec ID                                 : 55
Codec ID/Hint                            : MP3
Duration                                 : 3 min 53 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 kHz
Compression mode                         : Lossy
Stream size                              : 3.57 MiB (22%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 26  ms (0.65 video frame)
Interleave, preload duration             : 522  ms
Writing library                          : LAME3.98

HTTP request:

GET http://192.168.1.4:2283/api/assets/42d97d2d-ddf5-4927-ac8d-f668b19f10ce/video/playback?c=wF5Yg6bXYH+v4bpKDRiYJifdMmc=

Response:

HTTP/1.1 206 Partial Content
X-Powered-By: Express
x-immich-cid: levf7hn5
Cache-Control: private, max-age=86400, no-transform
Content-Type: video/avi
Accept-Ranges: bytes
Last-Modified: Thu, 11 Jul 2024 13:34:35 GMT
ETag: W/"105a3d6-190a200bcf1"
Content-Range: bytes 0-17146837/17146838
Content-Length: 17146838
Date: Sun, 14 Jul 2024 12:09:13 GMT
Connection: keep-alive
Keep-Alive: timeout=5

In the page, the request is aborted (NS_BINDING_ABORTED on Firefox, no content on Chrome). If the URL is opened in a new tab, the original AVI file is returned and download.

I tried re-running the transcoding task.

bo0tzz commented 1 month ago

Have you changed the transcoding configuration at all?

zdimension commented 1 month ago

Have you changed the transcoding configuration at all?

Actually, yes. Since other videos worked I didn't check that.

zdimension commented 1 month ago

@bo0tzz I think I know what's happening. The video can't be played in Chrome because it's an AVI file. But the codecs are good (H264 & MP3), so Immich doesn't transcode. It should be possible to choose, in addition to the allowed codecs, which container formats are allowed. My other AVI files have DivX or MJPEG video streams, often with PCM audio, so they were transcoded properly.

bo0tzz commented 1 month ago

That sounds plausible. @mertalev thoughts?

mertalev commented 1 month ago

We could add that. It feels bad to transcode just because of the container, but I guess it can't be helped in this case.

I'm not sure which containers are supported by which browser, so that needs some investigation.

mertalev commented 1 month ago

Would the preferred behavior be to remux the video as a different container (copying the streams), or to do a full transcode? The former is all that's actually needed here, but the latter is more storage-efficient.

zdimension commented 1 month ago

Would the preferred behavior be to remux the video as a different container (copying the streams), or to do a full transcode? The former is all that's actually needed here, but the latter is more storage-efficient.

IMO, the container issue should be treated separately from the codec issue, so if a file has an unacceptable container but acceptable streams, no transcode should be made, only remuxing. I understand how that could be debatable, though.

I'm not sure which containers are supported by which browser, so that needs some investigation.

mertalev commented 1 month ago

This should be fixed in the next release.