Optimze to a lossy format for video and image
Video (using ffmpeg):
apt install ffmpeg
Image (using caesiumclt binaries github): Download the binary using link https://github.com/Lymphatus/caesium-clt/releases
Download the binary of this repository: https://github.com/joojoooo/immich-upload-optimizer
# This is a task file for immich-optimizer (https://github.com/meichthys/immich-optimizer)
# It uses CaesiumCLT (https://github.com/CaesiumBased/CaesiumCLT) to optimize images.
#
# How to use:
# 1. Make sure you have caesiumclt and handbrake-cli installed and accessible in your system's PATH.
# 2. Save this content as `tasks.yml` in your immich-optimizer config directory.
# 3. Adjust the --quality and --audio-bitrate parameters to your liking.
tasks:
- name: caesium-image-optimization
# Defines the command to be executed.
#
# Parameters for caesiumclt:
# --quality 85: Sets the compression quality from 1-100. 85 is a good starting point,
# offering significant size reduction with minimal visible quality loss.
# Lower it for smaller files, or raise it for higher quality.
# --keep-exif: This is very important! It preserves all metadata from the original
# file, like GPS location, camera settings, and date taken.
# -o: Specifies the output directory, which is the result folder provided
# by immich-optimizer.
command: caesiumclt -q 85 -e --keep-dates "{{.folder}}/{{.name}}.{{.extension}}" -o "{{.result_folder}}"
# A list of file extensions that this task will process.
# CaesiumCLT supports JPEG, PNG, and WebP.
extensions:
- jpeg
- jpg
- png
- webp
# Optional: Uncomment the line below if you only want to process files larger than a certain size.
# The value is in bytes. For example, 1048576 is 1 MB.
# min_filesize: 1048576
- name: ffmpeg-video-optimization
# Makes a maximum video resolution to 1080p height
command: ffmpeg -hwaccel qsv -init_hw_device qsv=hw -filter_hw_device hw -i "{{.folder}}/{{.name}}.{{.extension}}" -map 0 -map_metadata 0 -vf "scale='if(gt(a,1),min(iw,1920),-2)':'if(gt(a,1),-2,min(ih,1080))'" -c:v h264_qsv -preset veryfast -b:v 0 -global_quality 23 -c:a aac -b:a 192k -movflags +faststart -y "{{.result_folder}}/{{.name}}.mp4"
# A list of video file extensions that this task will process.
extensions:
- mov
- mp4
- m4v
- avi
- wmv
- mkv
- flv
# Optional: Set a minimum file size (in bytes) to avoid processing very small files.
# min_filesize: 10485760 # Example for 10 MB [Unit]
Description=Immich Upload Optimizer Gateaway
After=network.target
[Service]
Type=simple
ExecStart=/root/immich-upload-optimizer -upstream http://192.168.0.108:2283 -tasks_file /root/config.yaml -listen ":2283"
Restart=on-failure
Environment="TMPDIR=/var/tmpfs"
[Install]
WantedBy=multi-user.target