Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): transcoding hardware acceleration #3171

Merged
merged 39 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d169bd1
added transcode configs for nvenc,qsv and vaapi
mertalev Jul 9, 2023
eb72b02
updated dev docker compose
mertalev Jul 9, 2023
cd3b063
added software fallback
mertalev Jul 9, 2023
a05e208
working vaapi
mertalev Jul 13, 2023
fdc8a1a
minor fixes and added tests
mertalev Jul 16, 2023
30566d3
updated api
mertalev Jul 16, 2023
1f00c16
compile libvips
mertalev Jul 17, 2023
0980472
move hwaccel settings to `hwaccel.yml`
mertalev Jul 17, 2023
1786319
changed default dockerfile, moved `readdir` call
mertalev Jul 18, 2023
3f76551
removed unused import
mertalev Jul 18, 2023
d6d2cd4
minor cleanup
mertalev Jul 18, 2023
c985dd2
fix for arm build
mertalev Jul 18, 2023
1e3c7f4
added documentation, minor fixes
mertalev Jul 21, 2023
0dcb80a
added intel driver
mertalev Jul 22, 2023
1552991
updated docs
mertalev Jul 22, 2023
6ccb3d6
uppercase codec and api names
mertalev Jul 22, 2023
93fad4a
formatting
mertalev Jul 22, 2023
b60f547
added tests
mertalev Jul 22, 2023
fcdbcc9
updated docs
mertalev Jul 22, 2023
1f6e09e
removed semicolons
mertalev Jul 22, 2023
0934774
added link to `hwaccel.yml`
mertalev Jul 22, 2023
1b9bce1
added newlines
mertalev Jul 22, 2023
55e3a92
added `hwaccel` section to docker-compose.prod.yml
mertalev Jul 22, 2023
86db57e
ensure mesa drivers are installed
mertalev Jul 22, 2023
f6682c6
switch to mimalloc for sharp
mertalev Jul 25, 2023
5f0cf74
moved build version and sha256 to json
mertalev Jul 25, 2023
d7cc8d1
let libmfx set the render device
mertalev Jul 25, 2023
ec86dc6
possible fix for vp9 on qsv
mertalev Jul 26, 2023
652c653
updated tests
mertalev Jul 26, 2023
85c1ccc
formatting
mertalev Jul 26, 2023
71696a8
review suggestions
mertalev Jul 26, 2023
2b4a1ea
semicolon
mertalev Jul 26, 2023
842a306
moved `LD_PRELOAD` to start script
mertalev Jul 26, 2023
f30f996
switched to jellyfin's ffmpeg package
mertalev Jul 31, 2023
5592052
fixed dockerfile
mertalev Jul 31, 2023
9a1f961
use cqp instead of icq for qsv vp9
mertalev Jul 31, 2023
f7bc02f
updated dockerfile
mertalev Jul 31, 2023
4702de7
added sha256sum for other platforms
mertalev Jul 31, 2023
254b7d6
fixtures
mertalev Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ jobs:
files: |
docker/docker-compose.yml
docker/example.env
docker/hwaccel.yml
*.apk
26 changes: 24 additions & 2 deletions cli/src/api/open-api/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ services:
immich-microservices:
container_name: immich_microservices
image: immich-microservices:latest
# extends:
# file: hwaccel.yml
# service: hwaccel
build:
context: ../server
dockerfile: Dockerfile
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ services:
immich-microservices:
container_name: immich_microservices
image: immich-microservices:latest
# extends:
# file: hwaccel.yml
# service: hwaccel
build:
context: ../server
dockerfile: Dockerfile
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ services:
immich-microservices:
container_name: immich_microservices
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
# extends:
# file: hwaccel.yml
# service: hwaccel
command: [ "start.sh", "microservices" ]
volumes:
- ${UPLOAD_LOCATION}:/usr/src/app/upload
Expand Down
23 changes: 23 additions & 0 deletions docker/hwaccel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.8"

# Hardware acceleration for transcoding - Optional
# This is only needed if you want to use hardware acceleration for transcoding.
# Depending on your hardware, you should uncomment the relevant lines below.

services:
hwaccel:
# devices:
# - /dev/dri:/dev/dri # If using Intel QuickSync or VAAPI
# volumes:
# - /usr/lib/wsl:/usr/lib/wsl # If using VAAPI in WSL2
# environment:
# - NVIDIA_DRIVER_CAPABILITIES=all # If using NVIDIA GPU
# - LD_LIBRARY_PATH=/usr/lib/wsl/lib # If using VAAPI in WSL2
# - LIBVA_DRIVER_NAME=d3d12 # If using VAAPI in WSL2
# deploy: # Uncomment this section if using NVIDIA GPU
# resources:
# reservations:
# devices:
# - driver: nvidia
# count: 1
# capabilities: [gpu]
60 changes: 60 additions & 0 deletions docs/docs/features/hardware-transcoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Hardware Transcoding [Experimental]

This feature allows you to use a GPU or Intel Quick Sync to accelerate transcoding and reduce CPU load.
Note that hardware transcoding is much less efficient for file sizes.
As this is a new feature, it is still experimental and may not work on all systems.

## Supported APIs

- NVENC
- NVIDIA GPUs
- Quick Sync
- Intel CPUs
- VAAPI
- GPUs

## Limitations

- The instructions and configurations here are specific to Docker Compose. Other container engines may require different configuration.
- Only Linux and Windows (through WSL2) servers are supported.
- WSL2 does not support Quick Sync.
- Raspberry Pi is currently not supported.
- Two-pass mode is only supported for NVENC. Other APIs will ignore this setting.
- Only encoding is currently hardware accelerated, so the CPU is still used for software decoding.
- This is mainly because the original video may not be hardware-decodable.
- Hardware dependent
- Codec support varies, but H.264 and HEVC are usually supported.
- Notably, NVIDIA and AMD GPUs do not support VP9 encoding.
- Newer devices tend to have higher transcoding quality.

## Prerequisites

#### NVENC

- You must have the official NVIDIA driver installed on the server.
- On Linux (except for WSL2), you also need to have [NVIDIA Container Runtime][nvcr] installed.

#### QSV

- For VP9 to work:
- You must have a 9th gen Intel CPU or newer
- If you have an 11th gen CPU or older, then you may need to follow [these][jellyfin-lp] instructions as Low-Power mode is required
- Additionally, if the server specifically has an 11th gen CPU and is running kernel 5.15 (shipped with Ubuntu 22.04 LTS), then you will need to upgrade this kernel (from [Jellyfin docs][jellyfin-kernel-bug])

## Setup

1. If you do not already have it, download the latest [`hwaccel.yml`][hw-file] file and ensure it's in the same folder as the `docker-compose.yml`.
2. Uncomment the lines that apply to your system and desired usage.
3. In the `docker-compose.yml` under `immich-microservices`, uncomment the lines relating to the `hwaccel.yml` file.
4. Redeploy the `immich-microservices` container with these updated settings.
5. In the Admin page under `FFmpeg settings`, change the hardware acceleration setting to the appropriate option and save.

## Tips

- You may want to choose a slower preset than for software transcoding to maintain quality and efficiency
- While you can use VAAPI with Nvidia GPUs and Intel CPUs, prefer the more specific APIs since they're more optimized for their respective devices

[hw-file]: https://github.com/immich-app/immich/releases/latest/download/hwaccel.yml
mertalev marked this conversation as resolved.
Show resolved Hide resolved
[nvcr]: https://github.com/NVIDIA/nvidia-container-runtime/
[jellyfin-lp]: https://jellyfin.org/docs/general/administration/hardware-acceleration/intel/#configure-and-verify-lp-mode-on-linux
[jellyfin-kernel-bug]: https://jellyfin.org/docs/general/administration/hardware-acceleration/intel/#known-issues-and-limitations
9 changes: 9 additions & 0 deletions docs/docs/install/docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ wget https://github.com/immich-app/immich/releases/latest/download/docker-compos
wget -O .env https://github.com/immich-app/immich/releases/latest/download/example.env
```

```bash title="(Optional) Get hwaccel.yml file"
wget https://github.com/immich-app/immich/releases/latest/download/hwaccel.yml
```

or by downloading from your browser and moving the files to the directory that you created.

Note: If you downloaded the files from your browser, also ensure that you rename `example.env` to `.env`.

:::info
Optionally, you can use the [`hwaccel.yml`][hw-file] file to enable hardware acceleration for transcoding. See the [Hardware Transcoding](/docs/features/hardware-transcoding.md) guide for info on how to set this up.
:::

### Step 2 - Populate the .env file with custom values

<details>
Expand Down Expand Up @@ -186,4 +194,5 @@ Immich is currently under heavy development, which means you can expect breaking

[compose-file]: https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
[env-file]: https://github.com/immich-app/immich/releases/latest/download/example.env
[hw-file]: https://github.com/immich-app/immich/releases/latest/download/hwaccel.yml
[watchtower]: https://containrrr.dev/watchtower/
3 changes: 3 additions & 0 deletions mobile/openapi/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/openapi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mobile/openapi/doc/AssetStatsResponseDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/openapi/doc/SystemConfigFFmpegDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions mobile/openapi/doc/TranscodeHWAccel.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/openapi/lib/api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mobile/openapi/lib/api_client.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mobile/openapi/lib/api_helper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions mobile/openapi/lib/model/asset_stats_response_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading