News:

2023-08-10 - ExifTool version 12.65 released

Main Menu

Detect corrupt CR2 files

Started by daniel97009, January 19, 2023, 09:58:22 PM

Previous topic - Next topic

daniel97009

Helping my wife who is a hobbyist photog but not tech savvy. USB drive corrupted (SMART says fine, of course) and of some 100K CR2 files an unknown % went bad. In some cases, entire files and/or folders vanished, which LR Classic will identify, in other cases, the files remain but the file is corrupted, which LR Classic does not seem to be able to detect unless you take certain actions on the individual file. There are sporadic backups, but not in a form where a "restore all" makes sense. My desire is to help her identify individual files that are (likely) corrupted across the entire collection. Checksum is not an option here. Helping her move to a NAS now, but sadly damage already done.

I understand that detecting corruption that affects quality of an image may not be possible. Instead, I'm hoping to identify files where the headers are so corrupted that it's pretty obvious the whole file is shot. I successfully used exiftool in one mangled folder to figure out which files were bad by trying extract jpgs. The ones that failed I deemed permanently lost. This worked great for a folder with a reasonable # of files, but what I did (create jpgs and see which files failed) doesn't scale to the 100K files across many hundreds of folders I need to scan. Anyone have any ideas on using exiftool to generate a command/script that will read from a input file of all files/folders I generate and write an output file that flags files that appear to have corrupt headers?

Thanks.

Phil Harvey

You could try something like this to detect severe corruption:

exiftool -if "not $filetype or $filetype ne 'CR2'" -directory=BADDIR -ext cr2 DIR

This command will move any file with a .cr2 extension that doesn't look like a cr2 file from the source directory DIR (and its subdirectories if you add the -r option) to the output directory (BADDIR -- call it what you want).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: daniel97009 on January 19, 2023, 09:58:22 PMby trying extract jpgs. The ones that failed I deemed permanently lost.

You might try Phil's extract_preview script as a last ditch attempt to get some usable previews out of the files.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

daniel97009

Brilliant Phil, thank you! Easier than I thought it would be.

I'll have to give the extract_preview a shot as well.

daniel97009

The extract_preview script worked quite well.

For Windows (Win10 in my case) users, I found I had to add the Win32-API package to my perl build from activestate.com for the script to save the recovered jpgs.