I had a 2 TB archive of photos and videos stored in inefficient formats. After recompressing them into modern ones, 700 GB were freed up and not a single file went missing.
Claude Code writes the script for this in a minute. The script isn't the hard part. Compression is re-encoding: every file is written again, with losses. Get the settings wrong and you've ruined memories you can't reshoot. So below is the prompt plus everything you need to do before and after it.
What you get
- Video → H.265 (HEVC). Apple says HEIF and HEVC compress better than JPEG and H.264 at the same visible quality.
- JPEG photos → HEIC (with
sips, built into macOS). - Compressed files go into a
compressed/folder next to the originals, with the same names. - Nobody deletes the originals. Checked ones are only moved to
to_delete/. You delete them yourself, by hand, once you've reviewed everything.
What you need: a Mac, Claude Code, ffmpeg (brew install ffmpeg), exiftool (brew install exiftool). sips, caffeinate and nice are already in macOS.
Step 1. Back up before any experiments
- Make a full copy of the archive on an external drive.
- Better, 2 copies, with one away from home: at relatives', at the office or in the cloud. One drive next to your laptop is just a second copy in the same apartment.
- Open a few photos and videos from different years from the copy. Make sure the copy works.
- Leave the Photos library alone. The script works only with regular folders. If your archive is in Photos, export the originals: File → Export → Export Unmodified Original. Apple exports them in their original format this way; a Live Photo comes out as 2 files, photo and video.
- Leave iCloud alone too: don't run the script on folders that sync. Work with a local copy.
Step 2. A test folder
- Copy a couple dozen files into a separate folder: different years, different cameras, phone and camera, long and short videos, a couple of Live Photos and RAW files if you have them.
- Do everything that follows on this folder first.
Step 3. The prompt for Claude Code
Open Claude Code in the test folder and paste:
Write a script to compress my photo and video archive on a Mac. Work only with the folder [path to the COPY of the archive or to the test folder]. Don't touch the Photos library or iCloud folders. What to do: - Video → H.265 with exactly these settings: ffmpeg -i INPUT -c:v libx265 -crf 23 -tag:v hvc1 -c:a aac -b:a 192k -map_metadata 0 OUTPUT.mp4 - JPEG photos → HEIC with sips. - Skip: RAW (.dng, .arw, .cr2, .cr3, .nef, .raf), PNG and anything already in HEVC or HEIC. - Skip Live Photos video: a short .MOV next to a photo with the same name. Safety rules: 1. Dry run first: just a list of what you'll compress, what you'll skip and why, and how much space you'll need. Change nothing until I say "go". 2. One folder at a time, no subfolders, until I explicitly allow it. 3. Write results to a compressed/ folder next to it, keep the same names. If a file already exists in compressed/, skip it, don't overwrite. Write to a temporary file first and rename only after the check, so a file cut off halfway never counts as done. 4. Never delete or overwrite originals. A checked original may only be moved to to_delete/, and ask me first. 5. Check every compressed file with ffprobe: duration matches the original, the file reads to the end without errors, it's smaller than the source. If it fails, keep the original, don't use the compressed file, note it in the report. 6. Keep metadata: capture date and location must survive (check with exiftool), copy the file modification date from the original (touch -r). 7. Before starting, check free disk space and tell me if it's enough. 8. Run through nice (low priority) and caffeinate -i (so the Mac doesn't sleep). 9. Keep a log: file, size before and after, check result, what was skipped and why.
Why these exact settings:
libx265 -crf 23gives higher quality than x265's default (CRF 28; the lower the number, the higher the quality and the bigger the file). This is my standard.-tag:v hvc1: without this tag, HEVC video may not open in QuickTime or on an iPhone. Apple's video requirements ask specifically forhvc1instead ofhev1.-map_metadata 0carries the metadata over from the source.
Step 4. The dry run
Claude Code shows a list. Read it yourself:
- is there anything on it that must not be touched (RAW, Live Photos, files from Photos);
- is there enough space: compressed copies are written alongside while the originals stay in place.
Only then say "go". On the test folder.
Step 5. Check the test
For every file in the test:
[ ] video duration matches the original [ ] the video opens and plays to the end (open a few yourself, in QuickTime and on your phone) [ ] the picture looks the same: open original and copy side by side, look at dark scenes and fine detail [ ] capture date is there [ ] location is there (especially for iPhone video) [ ] the file date in Finder matches the original [ ] the compressed file is smaller than the original [ ] the log is readable and matches what you see
If a date or location went missing, don't run it on the whole archive. Ask Claude Code to copy the metadata from the original (exiftool -tagsFromFile original copy) and check again.
Step 6. The archive, one folder at a time
- One folder → check the log → next one.
- You can leave the Mac alone:
nicekeeps it responsive,caffeinatestops it from sleeping in the middle of the night. - If the script stops, no problem: next run it skips finished files, and the half-written one stays under a temporary name, so you can delete it.
Step 7. Originals go last
The script puts checked originals into to_delete/. Don't delete them right away. Wait a week or two, look through the compressed files, make sure the backup is in place. Only then delete them, by hand.
What to skip
- RAW: their whole point is headroom for editing. Compression eats that headroom.
- Live Photos: photo and video live as a pair. Compress the video separately and the pair may fall apart.
- Already compressed (HEVC, HEIC): a second compression gains next to nothing and loses quality again.
- The Photos library and iCloud: exports and copies only.
If something goes wrong
- Stop the script: Ctrl+C in the terminal.
- The originals are intact; the script didn't delete them. Anything in
to_delete/goes back with a simple drag. - A compressed file is broken, cut short or missing its date: delete it from
compressed/, the original stays. - Something is missing from the originals: restore it from the backup (that's what step 1 and the 2 copies are for).
- The log shows which files were processed, which weren't and why, so you can see where to continue.
Sources
Facts checked November 2, 2026:
- Apple, Using HEIF or HEVC media on Apple devices
- Apple, Export photos, videos and slideshows (Photos for Mac)
- Apple, Back up your photo library on Mac
- Apple, HLS Authoring Specification, section 1.10 (
hvc1instead ofhev1) - x265, the --crf option (default 28, range 0–51)