How to deduplicate iMovie files in “Original Media”

disk-spaceimovievideo

With each project, iMovie imports videos, images, and audio into an iMovie Library.imovielibrary. I want my originals in a separate folder, along with other originals that I didn't import into iMovie and others for which I use other tools such as ffmpeg, but I still want to keep the ability to edit and export projects. At the moment I have videos in two places and the iMovie library is a bloated 300 GB in a 1 TB drive.

How can I avoid duplicating video or other files in an iMovie library and save disk space?

Best Answer

First a disclaimer: As you can see from miguelmorin's answer, some people have created various scripts to replace the duplicate images and videos in the iMovies library with hard links or symlinks. Before going any further, I would avoid hard links. Symlinks seem to work fine with iMovie, and hard links can have weird side effects, for instance Time Machine may back them up as separate files.

In my case, I used rdfind, which is an existing utility for cleaning up duplicate files and isn't specific to iMovie or even macOS.

  1. Install rdfind

    brew install rdfind
    
  2. Do a dry run

    e.g.

    rdfind -dryrun true -minsize 1048576 -makesymlinks true ~/Pictures/ ~/Movies/
    
    • -minsize is used to avoid touching any files that aren't image or video files. Adjust it as needed.
    • Replace ~/Pictures/ with the location(s) of the original image/video files. You can list as many directories as you want, but ~/Movies/ should be last because rdfind expects the locations of the original files to be listed first.

    Update: YMMV but it looks like iMovie 10 puts all of the original images and videos in Original Media directories under ~/Movies/iMovie Librarie.imovielibrary. This will go through those directories only and run rdfind on them, in which case -minsize shouldn't be needed (as above, replace ~/Pictures/ as needed):

    find ~/Movies/ -type d -name "Original Media" -exec rdfind -dryrun true -makesymlinks true ~/Pictures/ {} \;
    
  3. Create the symlinks

    Once you're happy with the output of the command from the dry run, remove -dryrun true to replace the duplicate files with symlinks, e.g.

    rdfind -minsize 1048576 -makesymlinks true ~/Pictures/ ~/Movies/
    

    Or:

    find ~/Movies/ -type d -name "Original Media" -exec rdfind -makesymlinks true ~/Pictures/ {} \;
    

Pros:

  • Dry run option to show you what it's going to do first
  • Will actually check the files to see if they're the same rather than just compare file names
  • Will find duplicates even if the filenames are different

Cons:

  • There's no way to restrict it to only image and video files (worked around above either by using -minsize or by only running rdfind on the Original Media directories)