Recover deleted AVI files from an SDHC card when you’ve emptied the trash, then repair them

Scenario: You’ve accidentally deleted a bunch of AVI files on an SDHC memory card. You’ve also emptied the Trash in OS X, which would ordinarily mean they’re permanently lost.

  • Install testdisk via Homebrew
  • Use mount to identify the disk format (in this case a FAT-32 partition from Keedox Trail camera)
  • Unmount the disk, diskutil unmount /dev/<whatever> (or you can open Disk Utility and use the GUI)
  • sudo diskutil (if you don’t run as root, chances are you won’t see the full list of drives)
  • Tell it to create a log when it asks you
  • The drive you want should be displayed without RO to indicate it’s accessible, select it
  • It’ll ask for partition type – for FAT-32 use Intel
  • Follow the rest of this procedure (you navigate to the correct partition, directory, the deleted files are in red, you press : (colon) to select them, then C to copy, choose a destination folder, etc.

AVI files not loading

I now had AVI files which were correctly named (apart from the initial _) and timestamped, but looked about twice as big as they should be and wouldn’t play due to unrecognisable header info.  They wouldn’t open in OS X Quick Look or VLC, DivFix++ kept giving me “Seek error” and trying to recover them by regenerating with ffmpeg:

ffmpeg -i input.avi -c copy output.avi

…didn’t work either.

The equivalent did work in mencoder though, and it’s very fast:

mencoder -idx input.avi -ovc copy -oac copy -o output.avi

I had a whole bunch of files (_ICT0001.AVI, _ICT0002.AVI etc.) for which you can use ‘find’ and a bash script:

find * -name '_ICT*.AVI' -type f -exec ~/ {} \; (test it on a single file first)

mencoder -idx $1 -ovc copy -oac copy -o repaired-$1