This use of GPAC may move closer to the goals you desire:
What is GPAC?
GPAC is an Open Source multimedia framework. GPAC is used for research and academic purposes and beyond through industrial collaborations! The project covers different aspects of multimedia, with a focus on presentation technologies (graphics, animation and interactivity) and on multimedia packaging formats such as MP4.
More details:
A little more research and an answer here provides the way!
We need several things installed, ideally with homebrew:
Reference
Now that you have the tools, try a script like this to convert images in a folder to HEIF/HEIC:
for F in *.jpg *.png *.tif *.tiff; \
do ffmpeg -i "$F" -crf 23 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -preset slower -pix_fmt yuv420p -f hevc "${F%.*}.hvc" && \
MP4Box -add-image "${F%.*}.hvc" -ab heic -new "${F%.*}.heic" && \
rm "${F%.*}.hvc";
done;
I tried it with a folder of images and it works. It turns images with odd dimensions to even dimensions, for instance, but besides a few caveats it works.
I don't think you should have to worry about the disk space being used by this. macOS should be treating that sort of thing as "Purgable", so if you are ever running low on space, macOS would automatically be able to remove that data to give you operational space back. So as far as space you can use on the disk, you should be able to consider the space currently used by that as free.
If it's a real bother though, your last option could be modified a little for reliability, which may solve the problem, depending on the Mac you have.
Basically, you could get a USB drive or SD Card of adequate size (also taking into consideration likely future needs, so say 32GB, or maybe 64GB, depends how many photos you take) and have it permanently connected. Instead of a Symlink, you could use macOS's fstab to cause the drive to use the com.apple.iLifeMediaBrowser.ILPhotosTranscodeCache
folder as it's mount point, both on boot and automatically when reconnected if it is ever removed while your system is running
A caveat of course, is that if your Mac is a portable, and you do take it places with you, this will be less convenient, since you still have to reconnect that drive every time you boot up. A Nifty Drive or JetDrive would solve this if it is a MacBook model with a SD slot and you don't use the slot... You can also get USB drives quite small now-a-days, think the size of a Logitech "Unified" wireless keyboard/mouse adapter, so you could safely leave that connected with a notebook, and it wouldn't be in the way on the back of a desktop, aside from of course having one less USB port.
Rough How-To
To do this, you would want to format the external drive/card to match the format of your internal drive.
With the newly created partition selected in Disk Utility, click the Info button (letter i in a circle) on the top right of the window, and then find the FileSystem UUID. Click on it, copy it with Command-V, and onwards to the Terminal!
In Terminal, you'll need to run the vifs
command as root, using sudo
.
vifs
uses the vi
text editor to modify fstab, after locking it so nothing damages it. If you don't know how to use vi
for text editing, type :h
and then the return key to get to the help text. It explains editing much better than I can ?
In short, use the arrow keys to get to the bottom empty line below the warning text about being careful with fstab, then type :i
to enter insert mode, and type:
UUID=<Your Filesystem UUID Here> /Users/<Your Home Folder Here>/Library/Containers/com.apple.MediaLibraryService/Data/Library/Caches/com.apple.iLifeMediaBrowser.ILPhotosTranscodeCache hfs rw
Replace HFS with whatever filesystem you formatted it as.
Exit Insert Mode with the ESC key, and type :wq
to write your changes and quit. If you want to quit and discard your changes, type :q!
instead.
After this, eject the drive/card, delete the contents of the cache folder and then insert the drive again. Should mount to that location and macOS will start dumping the cache data there again.
The Upsides
- Frees up space on internal drive permanently, while keeping that cache accessible for apps that may use it (you never know, you might just start)
- Fails gracefully if you remove the drive/card, as macOS will just act like when you deleted the contents and re-create the cache. When you re-attach the drive, it will mount back to the original location again, where-as with a symlink you may need to create the symlink all over again (depends if it was a clean unmount, and what happens when macOS tries to write through a broken symlink I guess, I'm not sure if it will destroy the symlink and change it back to a normal folder or just stop with an error
- Will always be mounted during startup, so it will be there from Boot to Shutdown for macOS to send data to
- One external drive could be used for multiple caches, if there are others you want a similar space saving from, but you would need a partition per cache. If you're using APFS on the external drive, this won't be a problem, as all APFS Partitions share the total storage of their drive (I do this with my Plex server's Transcode cache and Mobile Sync cache to spare partitions on my DAS, cause they just get so gorram big!)
The Downsides
- Not likely to be great if you use a NoteBook, unless you invest in a tiny USB drive or a form-fitted SD Card such as Nifty Drive or JetDrive
- Requires more hardware you may need to purchase
- Not 100% sure how macOS will react if you have a partially rebuilt cache in the library folder after the drive is disconnected, and then re-connect the drive/card and it mounts as the cache folder. My Plex caches haven't had a problem with that happening before since they don't re-populate when cleared until next time I'm watching/syncing something, but the macOS one might be interesting since it would start rebuilding straight away. Hopefully it would just delete what's in the cache at that point, or move it to the external drive/card. You might want to test that early on to see what happens
- You lose a USB port or a SD Slot, which may or may not be an issue, that depends on your needs
Again, macOS should dump those caches automatically if you ever actually need the cache, so you probably don't HAVE to do any of this, but if you really really want the space back, that is how I've done it on mine (Plex doesn't mark it's caches as pursuable for macOS, so it's this or manually clear them every now and then for me...)
Best Answer
To convert all
.HEIC
images in a directory to.png
Open terminal.
cd
to the directory where the.HEIC
files you want to convert are stored.Be careful, this will convert all .HEIC files in the directory - back them up first if you're not sure you want to do that just yet.
If you want to convert and resize images
The following will convert and resize images so the maximum height and width is
400
pixels (but you can change 400 below to any value)Be careful, this will convert and resize all .HEIC files in the directory - back them up first if you're not sure you want to do that just yet.
Reference