Wednesday, November 2, 2016

Recovering Jpeg Previews from Adobe Lightroom for Missing Photos

I'm sure there are many out there that have suffered the misfortune of accidentally deleting raw or other photo files (and emptying the trash), or having a disk crash beyond recovery.

In cases where you have merely delete files, recovery can usually be accomplished fairly easily using one of the many image recovery tools available for download. These tools however are beyond the scope of this post.

On the odd occasion for whatever reason it may be impossible to recover the original files. In such a case, there may be another, albeit next best option.

If you use Adobe Lightroom to manage your photos, and you still have the Lightroom catalog file and associated preview directory, there is a good chance that the previews of the missing photos are still stored by Lightroom. Depending on the size of the preview that you have set Lightroom to keep, you may be able to recover up to a full size Jpeg image (although it will show any development modifications you have made).

Background information on the Lightroom photo Library

A Lightroom photo library typically comprises two parts, namely:
  1. The catalog file, with a file extension .lrcat
  2. The preview directory, containing many sub directories and files with hexadecimal names.
For example, if you have a catalog called MyCatalog.lrcat, then your preview directory will be called "MyCatalog Previews.lrdata". Although on both PCs and Mac the preview storage location is actually a directory, on Macs, the directory appears as a package file, whose contents you can view if you choose to "Show Package Contents" on the right-click menu in Finder (if you have not turned on right-click for your mouse, then use Ctrl-Click).

If you venture into the lrdata directory, you will notice that it contains files with the extension .lrprev. These are the files that contain the Jpeg images which are your previews. Unfortunately, the Jpeg images are embedded inside the lrprev file (usually at up to 7 different sizes/levels), which makes them difficult to retrieve without a bit of programming trickery. Although Adobe has published a Lightroom script for extracting previews, I have found it to be unreliable, in that it doesn't seem to extract previews for all images that have previews.

Doing the deed

If you have a Mac or a Linux based PC, you are in luck, as I have written a shell script to extract previews from a Lightroom library of your choice. If you have a PC, it is possible that this script may work in Cygwin. I have yet to test it. Alternately, you could copy the lrcat and lrdata file and directory to an external disk and plug it into a Mac or Linux PC if you have one available.

If you would like to recover the original names of your images, then you need to ensure that SQLite3 is correctly installed on your system.

These instruction assume you already have basic understanding of using the Command Line in terminal on your Mac/Linux machine. 

To recovery your Previews, to do the following:
  1. Unzip and copy the script to a suitable location on your machine and take note of the file path.
  2. Open a terminal window.
  3. Make the script executable my entering:
    chmod 755 /path/to/extractJPGFromPreviews
  4. Change directory to the location of your Lightroom catalog:
    cd /path/to/the/lrcat
  5. Run the script as follows:

    /path/to/extractJPGFromPreviews MyCatalog.lrcat OUTPUTSUBDIRECTORY

    Where OUTPUTSUBDIRECTORY is an option name for a subdirectory/folder to store the Jpeg files.
All going well, the script will extract the largest available preview image for each image that has a preview available.

Please Note: This script comes with no guarantee of success.

If you found this script useful, 
then a donation would be greatly appreciated.

You are also welcome to like my Facebook page.

Thanks! Your Support is appreciated.