Language EN FR

How to deduplicate HEIC, RAW, Live Photos, and videos in Nextcloud without breaking Photos or Memories

Photo and video libraries routinely consume 60% to 85% of a self-hosted Nextcloud server's disk capacity, yet exact byte-level deduplicators miss the largest share of media waste: iPhone HEIC-to-JPEG conversions, DSLR bursts, WhatsApp re-compressions, and re-wrapped MP4 clips. This engineering guide explains how to clean photo and video duplicates cleanly across Nextcloud 28 to 35 while keeping oc_filecache, Nextcloud Photos, Nextcloud Memories, and appdata_*/preview healthy.

Published December 1, 2026 by André Théo Lauret (Eclipse Technology) · Maintainer of Duplicate Finder (v1.11.1, AGPL-3.0) · Companion: Duplicate Finder Pro v0.2.0

Direct answer for Nextcloud photo administrators

To deduplicate HEIC, RAW, Live Photos, and videos in Nextcloud without breaking oc_filecache, Photos, or Memories, combine exact SHA-256 hashing with 64-bit perceptual dHash clustering and burst EXIF windows, then delete exclusively via Nextcloud's native Node::delete API. Never run fdupes or rm inside data/ or appdata_*/preview; finish with occ files:cleanup, occ preview:cleanup, and occ memories:index.

1. Why Nextcloud photo libraries accumulate silent duplicates

In our earlier runbook on removing duplicate files safely without breaking oc_filecache, we covered why raw shell deletion inside data/ corrupts folder ETags and triggers zombie re-uploads from desktop clients. Photo and video libraries introduce an additional layer of complexity because most duplicate media files on a real Nextcloud instance are not byte-identical.

Across family clouds, creative agencies, and small business Nextcloud deployments, five recurring workflows create gigabytes of near-duplicate photos and bloated preview caches:

iOS HEIC-to-JPEG conversion drift

The Nextcloud iOS Auto Upload setting can convert Apple HEIC shots into JPEG on upload, while a laptop backup or AirDrop import later copies the original .HEIC file into another folder. Both files depict the exact same frame with completely different SHA-256 digests and sizes.

Apple Live Photo pairs (HEIC + MOV)

Each Live Photo consists of a still image paired with a 1.5 to 3 second .MOV companion clip sharing an EXIF content identifier. Re-importing camera rolls across devices duplicates both files, and naive cleanup scripts often remove only the video or only the still.

DSLR RAW + JPEG and burst series

Cameras shooting CR3, NEF, ARW, or DNG alongside preview JPEGs double storage immediately. Add 8-frame handheld bursts taken within two seconds and 85% of the folder consists of slightly softer redundant shots.

Messaging re-compression & Takeout

Shared family albums, WhatsApp or Signal exports, and overlapping Google Takeout archives re-save the same photo at 1600px JPEG with stripped EXIF tags. Even worse, every redundant photo generates multiple thumbnail resolutions inside appdata_<id>/preview/.

Because Nextcloud Photos and Nextcloud Memories both rely on the relational fileid key stored in oc_filecache (with Memories maintaining its own timeline, EXIF, and geospatial indexes in oc_memories tables), deleting media files out-of-band creates double damage: stale timeline thumbnails in Memories and orphaned thumbnail trees inside appdata_<id>/preview/ that silently consume 20% to 40% of your remaining SSD space.

2. SHA-256 vs pHash/dHash vs EXIF burst and video fingerprinting

Choosing the right detection algorithm determines both how much disk space you reclaim and how low your false-positive rate stays. Exact cryptographic hashing is always your first pass because its false-positive probability is zero, but media archives require perceptual and metadata-aware engines on top.

Detection method How it compares media Catches HEIC vs JPEG / resized Catches bursts & RAW+JPG Catches re-encoded videos Best operational role
Exact SHA-256 / MD5 hash Byte-for-byte digest of entire file payload. No. Any EXIF edit or re-encode changes the hash. No. Only catches identical copies of the same file. No. Re-muxing MP4 to MKV changes every byte. Mandatory Pass 1 via free Duplicate Finder OSS (zero false positives).
64-bit dHash (Difference Hash) Resizes to 9x8 grayscale and compares adjacent horizontal pixel gradients. Yes. Robust to JPEG/HEIC recompression and resizing (Hamming <= 8). Partial. Catches visually near-identical frames in bursts. Keyframes only when paired with a frame extractor. Fastest perceptual image engine in PHP (used by Duplicate Finder Pro).
64-bit pHash (DCT Perceptual) Applies 2D Discrete Cosine Transform on a 32x32 grayscale matrix and keeps low frequencies. Yes. Slightly more tolerant of subtle gamma or watermark shifts. Partial. Higher CPU cost per image than dHash. Keyframes only; heavier on large NAS libraries. Useful for heavy edits, slower on low-power ARM/NAS CPUs.
EXIF Burst + Laplacian Sharpness Clusters photos by EXIF DateTimeOriginal <= 2.0s + dHash distance + edge sharpness variance. Yes. Groups HEIC, AVIF, WebP, and camera RAW together. Yes. Scores RAW tier, resolution, and sharpest focus frame automatically. No (still photography focused). Dedicated DSLR/smartphone burst triage (Pro Pack 2).
Multi-keyframe Video Fingerprint Streams keyframes at 10% / 35% / 65% / 90% duration via ffmpeg pipe:1 plus duration tolerance. Not applicable (video containers). Not applicable (video streams). Yes. Spots 4K vs 1080p transcodes and re-muxed .mov/.mp4/.mkv. Reclaiming multi-gigabyte video bloat safely (Pro Pack 3).

Why does Duplicate Finder Pro standardize on 64-bit dHash rather than heavy neural embeddings on a Nextcloud host? Most self-hosted Nextcloud instances run on modest VPS nodes, Hetzner root servers, or home NAS boxes without a dedicated GPU. Computing a 64-bit dHash requires only a tiny grayscale downsample and 64 integer comparisons, yielding a deterministic Hamming distance from 0 (visually identical) to 64 (completely unrelated).

With the default threshold of --threshold=8 (87.5% bit similarity), dHash reliably clusters an iPhone .HEIC original with its converted .JPG export and a 1600px WhatsApp copy, while separating distinct portraits or scenes cleanly. For burst sequences where a subject moves slightly between shutter clicks, combining an EXIF DateTimeOriginal window of <= 2.0 seconds with a relaxed dHash ceiling (<= 14) keeps false merges near zero without demanding GPU hardware.

3. Protecting Apple Live Photos, RAW masters, and appdata_*/preview

Three failure modes turn a well-intentioned photo cleanup into a broken Nextcloud gallery. Understanding how Nextcloud stores companion assets and thumbnails prevents all three.

Why Apple Live Photos need pair-aware deletion

Nextcloud Photos and Nextcloud Memories pair an iOS still image (IMG_4821.HEIC) with its short companion video (IMG_4821.MOV) using matching basenames and Apple QuickTime/EXIF metadata. If an exact-hash tool discovers that two identical .MOV clips exist across /Photos/2026/ and /Imports/iPhone-Backup/, deleting the video inside /Photos/2026/ while keeping the copy in /Imports/ breaks the Live Photo in your main timeline.

In Duplicate Finder v1.11.1, LivePhotoDeletionService enforces strict pair semantics inside FileService::deleteFile(): deleting a standalone Live Photo video component is blocked outright, and removing a complete Live Photo pair is only permitted when another complete surviving pair exists elsewhere and neither path resides inside a protected Origin Folder.

Why you must never run rm on appdata_<instanceid>/preview/

Nextcloud generates cached thumbnails at multiple widths and stores them under data/appdata_<instanceid>/preview/<fileid-sharded-path>/. Every single cached thumbnail also has a row inside oc_filecache under the appdata_<instanceid> path. When a user uploads 40,000 duplicate photos and Preview Generator or Memories renders thumbnails for them, appdata_*/preview/ can easily grow to 80 GiB or more.

When you remove duplicate photos through Nextcloud's VFS (OCP\Files\Node::delete()), Nextcloud hooks trigger preview cleanup for the deleted fileid. Conversely, if an administrator tries to free space quickly by running rm -rf data/appdata_*/preview/* from bash, Nextcloud's database still believes those preview files exist, causing blank squares across Nextcloud Photos and Memories until you run a slow occ files:scan-app-data pass. Always use native VFS deletion followed by occ preview:cleanup.

Preserving tags, favorites, and comments when merging duplicate photos

Users frequently favorite a JPEG copy in Nextcloud Photos or add tags and comments in a shared family album while the unedited HEIC or RAW master sits untouched in an archive folder. Deleting the annotated copy naively loses those collaborative signals. Duplicate Finder Pro v0.2.0 (Pack 4 metadata merge) transfers Nextcloud system tags, favorites, and comments onto the surviving master fileid before moving the redundant copy to files_trashbin.

4. Nextcloud config.php and ImageMagick HEIC prerequisites

Before running perceptual scans or generating Memories thumbnails for modern mobile photography, verify that your PHP runtime can decode HEIC/HEIF, AVIF, and camera RAW files. On Debian and Ubuntu servers, install imagemagick, libheif1, php-imagick, and ffmpeg, then verify that ImageMagick lists HEIC and AVIF in its supported formats.

Inside Nextcloud's config/config.php, remember that enabledPreviewProviders acts as an explicit allowlist: once you define the array, any provider omitted from the list is disabled. Include OC\Preview\HEIC and OC\Preview\Movie alongside standard image formats:

PHP (config/config.php)HEIC, WebP, and Video preview providers for Photos & Memories
'enable_previews' => true,
'preview_max_x' => 2048,
'preview_max_y' => 2048,
'preview_max_memory' => 512,
'enabledPreviewProviders' => [
    'OC\\Preview\\PNG',
    'OC\\Preview\\JPEG',
    'OC\\Preview\\GIF',
    'OC\\Preview\\BMP',
    'OC\\Preview\\WebP',
    'OC\\Preview\\HEIC',
    'OC\\Preview\\Movie',
    'OC\\Preview\\MarkDown',
    'OC\\Preview\\TXT',
],

Verify host binary support before scheduling any perceptual scan or preview regeneration job:

Bash (Host verification)Check ImageMagick libheif, PHP Imagick, and FFmpeg
# Confirm ImageMagick supports HEIC and AVIF decoding
convert -list format | grep -iE 'HEIC|HEIF|AVIF|DNG|CR2'

# Confirm PHP CLI loads the imagick and sodium extensions
php -m | grep -iE 'imagick|sodium|exif'

# Confirm ffmpeg is available for video keyframe fingerprinting
ffmpeg -version | head -n 2

5. Step-by-step occ runbook: deduplicate Photos and sync Memories

Execute the cleanup in four controlled phases. Every audit and perceptual scan runs strictly in read-only or --dry-run mode first so you can inspect exact reclaimable gigabytes before moving a single photo to the trashbin.

Phase 1: Measure photo formats and appdata preview footprint in oc_filecache

Run a read-only SQL query against your Nextcloud database (PostgreSQL or MariaDB/MySQL) to see how much storage is locked in HEIC, RAW, JPEG, video files, and appdata_*/preview/ thumbnails:

SQL (read-only diagnostic)Photo extensions and preview cache size in oc_filecache
SELECT
  CASE
    WHEN path LIKE 'appdata_%/preview/%' THEN 'appdata_preview_cache'
    WHEN LOWER(name) LIKE '%.heic' OR LOWER(name) LIKE '%.heif' THEN 'heic_heif'
    WHEN LOWER(name) LIKE '%.cr2' OR LOWER(name) LIKE '%.cr3'
      OR LOWER(name) LIKE '%.nef' OR LOWER(name) LIKE '%.arw'
      OR LOWER(name) LIKE '%.dng' THEN 'camera_raw'
    WHEN LOWER(name) LIKE '%.jpg' OR LOWER(name) LIKE '%.jpeg' THEN 'jpeg'
    WHEN LOWER(name) LIKE '%.mov' OR LOWER(name) LIKE '%.mp4'
      OR LOWER(name) LIKE '%.mkv' THEN 'video_mov_mp4_mkv'
    ELSE 'other'
  END AS media_bucket,
  COUNT(*) AS file_count,
  ROUND(SUM(CASE WHEN size > 0 THEN size ELSE 0 END) / 1073741824.0, 2) AS total_gib
FROM oc_filecache
WHERE size > 0
GROUP BY media_bucket
ORDER BY total_gib DESC;

Phase 2: Eliminate exact duplicates first with Duplicate Finder OSS

Always clear byte-identical copies first using the open-source Duplicate Finder app. Doing so reduces the number of files that need perceptual decoding in Phase 3 and immediately catches duplicated camera backup folders:

Bash (Nextcloud occ)Pass 1 exact-hash audit on photo libraries
# 1. Index a single user's Photos library first to benchmark disk throughput
sudo -u www-data php occ duplicates:find-all --user=alice --path="./Photos"

# 2. Check reclaimable storage from exact duplicates above 2 MiB
sudo -u www-data php occ duplicates:stats --user=alice --min-size=2M --top=15 --output=table

# 3. Spot entire duplicated camera-import folders (e.g. old DCIM copies)
sudo -u www-data php occ duplicates:folders --user=alice --min-files=5 --min-size=50M

Before triggering deletion in the Duplicate Finder web UI, declare your authoritative archive paths (for example /Photos/Originals or /Photos/RAW-Masters) as Origin Folders. Every deletion then runs through OCP\Files\Node::delete(), updates oc_filecache atomically, respects Live Photo pairs, and moves removed copies into files_trashbin.

Phase 3: Detect HEIC/JPEG duplicates, RAW bursts, and re-encoded videos

Once exact copies are gone, run perceptual 64-bit dHash clustering and multi-format media scans with Duplicate Finder Pro v0.2.0 (19 EUR one-time offline Ed25519 license, zero external telemetry). All external binaries (ffmpeg, fpcalc) execute via strict proc_open argument arrays with zero shell interpolation:

Bash (Nextcloud occ)Pass 2 perceptual dHash, HEIC/RAW bursts, and video keyframe dry-run
# 1. Verify offline Ed25519 license status
sudo -u www-data php occ duplicatefinder_pro:license:status

# 2. Cluster visually similar photos (HEIC vs JPEG, WhatsApp exports) with 64-bit dHash
sudo -u www-data php occ duplicatefinder_pro:perceptual:scan \
  --threshold=8 --strategy=smart_master --dry-run --format=text

# 3. Group HEIC/AVIF/RAW camera bursts within a 2-second EXIF DateTimeOriginal window
sudo -u www-data php occ duplicatefinder-pro:scan-formats \
  --pack=photos --burst-window=2 --dry-run --format=json > /tmp/photo-bursts-audit.json

# 4. Detect re-encoded or re-muxed videos via 4-keyframe signatures (10%/35%/65%/90%)
sudo -u www-data php occ duplicatefinder-pro:scan-formats \
  --pack=media --duration-tolerance=2 --dry-run --format=text
Duplicate Finder Pro v0.2.0 dashboard inside Nextcloud 35 showing Format Packs for HEIC/RAW bursts, perceptual clustering, and governance reports
Duplicate Finder Pro v0.2.0 running in Nextcloud 35 Administration Settings: multi-user governance, 4 exclusive Pro Format Packs (Documents SimHash, Modern Photos HEIC/RAW bursts, Video/Audio keyframes, Zero-Extraction Archives), cleanup policies, and offline Ed25519 verification.

Phase 4: Reconcile oc_filecache, reclaim preview bloat, and re-index Memories

After reviewing the dry-run reports and executing safe VFS deletions (and letting users confirm their trashbin recovery window), reclaim orphaned preview thumbnails and refresh the Nextcloud Memories timeline index cleanly:

Bash (Nextcloud occ)Post-cleanup hygiene for Photos, Preview Generator, and Memories
# 1. Clean unreferenced oc_filecache rows (fast, safe online)
sudo -u www-data php occ files:cleanup

# 2. Purge orphaned thumbnail files in appdata_<id>/preview/
sudo -u www-data php occ preview:cleanup

# 3. Synchronize Nextcloud Memories timeline and EXIF index
sudo -u www-data php occ memories:index

# 4. Optional: pre-generate thumbnails for newly consolidated folders (Preview Generator app)
sudo -u www-data php occ preview:pre-generate

# 5. Verify the SHA-256 hash-chained audit log in Duplicate Finder Pro
sudo -u www-data php occ duplicatefinder_pro:audit:verify

6. Smart Master ranking for DSLR RAW, bursts, and Google Takeout

The hardest decision during photo deduplication is not detecting that five files show the same sunset; it is guaranteeing that automated retention keeps the right master file every single time. File size alone fails because a bloated uncompressed PNG screenshot can outweigh a clean HEIC original, and modification time fails because Google Takeout and iCloud exports frequently reset filesystem mtime to the archive extraction date.

Duplicate Finder Pro Pack 2 (ModernPhotoBurstService) resolves burst and cross-format clusters using a deterministic four-factor Smart Master scoring model:

  1. Format fidelity tier: Camera RAW formats (CR2, CR3, NEF, ARW, DNG) rank highest, followed by lossless formats (TIFF, PNG), modern high-efficiency mobile originals (HEIC, HEIF, AVIF, WebP), and standard JPEG exports last.
  2. Pixel resolution: Full-sensor dimensions automatically beat 1600px messaging exports or cropped thumbnails.
  3. Laplacian variance sharpness: Inside a 2-second burst sequence where every shot shares the same format and resolution, a 2D discrete Laplacian filter measures edge energy across the grayscale matrix so focused frames score higher than motion-blurred shots.
  4. EXIF integrity and priority folders: Files retaining intact DateTimeOriginal, camera model, and ISO/shutter metadata outrank stripped copies, while Origin Folders always win as protected masters.

If your organization also manages shared Nextcloud servers across multiple departments or needs SLA-backed Nextcloud upgrade and storage engineering, check our Open Source Pro Support & SLA page or manage licenses and invoices directly inside the Eclipse Client Portal.

7. Frequently asked questions

Why does SHA-256 hashing miss duplicate HEIC, JPEG, and WhatsApp photos in Nextcloud?

SHA-256 compares exact raw bytes, so changing a single EXIF timestamp, re-encoding an iPhone HEIC capture into JPEG during upload, or saving a resized copy from WhatsApp produces a completely different hash. Perceptual 64-bit dHash compares grayscale luminance gradients instead of raw bytes, matching re-compressed and resized photos reliably with a configurable Hamming distance threshold.

Will deduplicating photos break Nextcloud Memories timelines, albums, or Live Photos?

Deleting photos via Nextcloud's virtual filesystem (OCP\Files\Node::delete) preserves database integrity across oc_filecache and lets Memories reconcile timeline items cleanly when you run occ memories:index afterward. To avoid breaking Apple Live Photos, use a tool with a dedicated Live Photo pair guard so companion MOV clips are never orphaned from their HEIC still images, and keep curated folders in Origin Folders.

Can I delete appdata_*/preview manually to reclaim space after cleaning duplicate photos?

Never delete directories inside appdata_<instanceid>/preview/ directly with rm while Nextcloud is running, because oc_filecache tracks every preview file as an appdata entry. Instead, run occ files:cleanup and occ preview:cleanup after removing duplicate photos through the VFS, or run occ files:scan-app-data during a maintenance window if orphaned thumbnails remain.

How should I handle DSLR RAW + JPEG pairs (CR3, NEF, ARW, DNG) without losing the RAW master?

Configure a retention strategy that ranks format fidelity before file size or age. In Duplicate Finder Pro v0.2.0, Pack 2 (Modern Photos & Bursts) and the smart_master selector score RAW formats (CR2, CR3, NEF, ARW, DNG) above lossless TIFF/PNG, modern HEIC/AVIF, and standard JPEG, while factoring in resolution and Laplacian sharpness variance so the sharpest RAW master is kept automatically.

What ImageMagick and Nextcloud config.php settings are required for HEIC and video deduplication?

Install ImageMagick compiled with libheif support (php-imagick) and explicitly whitelist OC\Preview\HEIC alongside standard image providers inside enabledPreviewProviders in config.php. For video keyframe fingerprinting in Duplicate Finder Pro Pack 3, install ffmpeg on the host so multi-keyframe signatures stream through proc_open and pipe:1 without writing temporary extracts to disk.

Reclaim Nextcloud photo and video storage safely, 100% offline

Start with free open-source Duplicate Finder v1.11.1 (AGPL-3.0) for exact SHA deduplication, Origin Folders, and Apple Live Photo protection on Nextcloud 28 to 35. Upgrade to Duplicate Finder Pro v0.2.0 (19 EUR one-time offline Ed25519 license) for 64-bit dHash perceptual clustering, HEIC/AVIF/RAW burst scoring, video keyframe fingerprinting, and metadata-preserving merges.