Skip to content

Instantly share code, notes, and snippets.

@Thinkscape
Last active January 9, 2026 11:07
Show Gist options
  • Select an option

  • Save Thinkscape/b6196a17cefab450914a79f0f0b56292 to your computer and use it in GitHub Desktop.

Select an option

Save Thinkscape/b6196a17cefab450914a79f0f0b56292 to your computer and use it in GitHub Desktop.
Check all assets' encoded video files - if a file is missing, set to empty in the database so that it can be re-encoded
#!/bin/bash
# Instructions for running inside docker:
# 1. Exec into a container, i.e. with: docker exec -it c0nta1ner1d bash
# 2. Copy or create the script and make it executable with: chmod +x script.sh
# 3. Install deps with: apt update && apt install -y postgresql-client
# 4. Run it and wait until finished.
# 5. Go to Immich web and into Administration
# 6. Go to Jobs and scroll down to TRANSCODE VIDEOS
# 7. Click MISSING
# Default values when running immich in a docker container
DB_NAME="immich"
DB_USER="postgres"
DB_PASSWORD="postgres"
DB_HOST="db"
DB_PORT="5432"
PATH_PREFIX="/usr/src/app/"
# Export the password for non-interactive authentication
export PGPASSWORD="$DB_PASSWORD"
# Query the assets table to find records with non-empty encodedVideoPath
query="SELECT id, \"encodedVideoPath\" FROM assets WHERE \"encodedVideoPath\" IS NOT NULL AND \"encodedVideoPath\" != '';"
# Execute the query and iterate over each record
psql -U "$DB_USER" -d "$DB_NAME" -h "$DB_HOST" -p "$DB_PORT" -t -c "$query" | while read -r line; do
IFS='|' read -r id encodedVideoPath <<< "$(echo "$line" | xargs)"
id=$(echo "$id" | xargs)
encodedVideoPath=$(echo "$encodedVideoPath" | xargs)
# Check if the file exists
fullPath="${PATH_PREFIX}${encodedVideoPath}"
if [ ! -f "$fullPath" ]; then
# If file does not exist, update the encodedVideoPath to an empty string
update_query="UPDATE assets SET \"encodedVideoPath\" = '' WHERE id = '$id';"
psql -U "$DB_USER" -d "$DB_NAME" -h "$DB_HOST" -p "$DB_PORT" -c "$update_query"
echo "🔴 Video missing for asset id $id - set encodedVideoPath to an empty string."
else
echo "🟢 Video exists for asset id $id."
fi
done
# Unset the password variable for security
unset PGPASSWORD
@dionorgua
Copy link

dionorgua commented Jan 9, 2026

Hi there from 2026. This script is still useful. It doesn't work anymore as is (because table was renamed to asset). But should be OK after this.

After manipulation with transcode settings and removing folder with encoded video multiple times I found that some of videos doesn't play at all. And log shows file not found error. And it still same, "Transcode MISSING" job do nothing to fix it.

I was not able to quickly find how and where to run this script (because imimich postgres container has no access to media files). So I modified it to run psql via docker exec once (docker exec -i immich_postgres psql -U "$DB_USER" -d "$DB_NAME" -t -c "$query"). And update part was changed to just print comma-separated list of 'id', to file.

Then I just added prefix/suffix manually and got followed SQL query:

UPDATE asset SET "encodedVideoPath" = '' WHERE id IN (
'24d29864-2748-4675-a85a-c035e1763397',
'3982a65c-5cc5-4902-b5ae-08f02fc8a061',
...
'4efb617b-6ed9-43c6-bf11-c556140ea5f1');

I executed it manually via docker exec -i immich_postgres psql --dbname=immich --username=postgres < /tmp/rm_transcodes.sql

Thanks for saving my time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment