Recovering corrupted .nef files

DSC_0363.NEF (21.0 MB)

I attached one of the files to illustrate the problem.

@PaperDigits, I’ll try this out tomorrow (have to get some sleep now). Is this designed to find lost pictures or to repair damaged/corrupted files?

Find files on corrupted disks.

I couldn’t open it with any of the raw converters I have. I ran exiftool on it to look at the metadata, which appears to be intact, as well as the JpgFromRaw and PreviewImage jpegs that NEFs normally contain. I did find another image, called “OtherImage”, it extracted to another jpeg.

What are you camera model and raw converter name/version?

If this NEF is consistent with the others, you should at least be able to salvage the embedded jpeg.

1 Like

Hi Glenn, thanks for the effort!
The camera is a Nikon D5300.

My wife uses Photoshop (my efforts to convert remain fruitless… ) and I am more a Gimp/G’mic hobbyist, but I normally don’t use raw myself.

What would the best way be to try to salvage the embedded JPEG?

Edit: spelling

@Narayan As a fellow hobbyist, I hope I can help. See below.

Exiftool

A day ago I wrote a post on exiftool that you might find useful: [Solved] Fast raw to jpg? - #11 by afre. The largest embedded image is probably PreviewImage but follow the instructions to find out.


PhotoRec

PhotoRec and TestDisk are a powerful set of tools. They are not the easiest to use but I have recovered seemingly unrecoverable files and filesystems with them. When you first use PhotoRec, the results may be disappointing. Just tweak the settings and try again until you get a desired outcome.

Advice based on my personal experience:

  1. File loss and / or corruption: along the way, something went wrong. Maybe it had to do with the copying over, or maybe it had to do with the integrity of SD card or hard drive or their controllers… Looks like there were multiple points where something could have gone wrong.

  2. Start as close to where the files were generated as possible. That would be the SD card. Since it is relatively inexpensive to replace, don’t take another chance with it in the future. It might fail on you again.

  3. Make a disk image of the card in case it is faulty (or file / folder image if you are dealing with individual folders / files). That way you can use an app like PhotoRec, which can wear the card even more, without worrying about it dying completely.

    Edit: please note that this image must be written to a separate hardware storage device, otherwise this precaution won’t work. Also, consider generating an image that is a bit-by-bit copy. It is a much slower and resource heavy process but it is worth it for apps that can take advantage of that.

  4. Do multiple searches with the same and different settings.

  5. Depending on your settings, the file type you are looking for, and how corrupt or old (overwritten) the files are; you might get files that are unnamed or have a funny name. Files can also have missing metadata, as you described above, or they may be missing information (partial images). You may find traces of very old files if they weren’t overwritten enough to disappear completely.

2 Likes

Hello @Narayan I just changed the name of the topic from a general problem to the specific one. It will be easier for future reference. I hope you do not mind.

Hi Afre, thanks a lot for your detailed explanation.

I think the problem originates from the macbook, where we had to move the folder with the images from the desktop because it was slowing down/freezig the system.

The sd card has been used since, also during our journey, but I’ll give it a try anyway.

Ps: I don’t mind the title change at all.

@Narayan Which MacBook model and OS version were you using?

As mentioned, there might be one or a number of points of failure, so I would start with the SD card and then move along the file transfer timeline.

Because you used the SD card after encountering the problem, chances are that some or all of the files that you would like to recover have been partially or fully overwritten to the point where recovery isn’t easy. So, you would still benefit from checking the files on the MacBook and then on the workstation.

Again, it would be wise to create an image of those files or folders on a separate disk, so that when you examine them you wouldn’t risk further hardware, software or firmware failure.

You can use this perlscript to recover your pictures: https://owl.phy.queensu.ca/~phil/exiftool/fix_corrupted_nef.html. Use “12 bit”.

DSC_0363.NEF (21.0 MB)

8 Likes

Someone buy this guy a beer. Nice find on a solution, @Thomas_Do!

1 Like

Just know what this utility is and isn’t for (as detailed on the page). It will definitely modify your files; backup before using it.

As far as I can see it just produces a new output file. But I did not check the code. So, better safe than sorry :-).

Here is an anecdote that illustrates the importance of backing up:

A few years ago, when I was recovering a friend’s lost data, Windows kindly offered to fix a corrupted SD (or group of files – don’t remember which). I was sleepy and did not realize that I had clicked yes. The fix turned out to be something undesirable but there was no going back. It made the recovery much harder, and impossible for certain images.

As others have pointed out exiftool can do this.

I ran the following on your sample NEF:

$ exiftool -s DSC_0363.NEF |grep Binary
...
JpgFromRaw                      : (Binary data 2520615 bytes, use -b option to extract)
OtherImage                      : (Binary data 813454 bytes, use -b option to extract)
PreviewImage                    : (Binary data 132826 bytes, use -b option to extract)
ThumbnailTIFF                   : (Binary data 57816 bytes, use -b option to extract)

The biggest image is the JpgFromRaw, so that’s what you should probably salvage. Here’s the command that would do that:

$ exiftool -b -JpgFromRaw DSC_0363.NEF > DSC_0363.jpg

2 Likes

Hi everyone, what an awesome community! Thanks a lot for all your valuable advice and hard work! I’ll try out the suggested methods, but family life and work are preventing me from getting a lot of computer time. As soon as I try this out I’ll give you feedback!

2 Likes

@Narayan

I first tested the procedure on linux (my favorite OS :slight_smile: ) but it also works fine on windows.

Choose a disk with a lot of space
Download http://owl.phy.queensu.ca/~phil/exiftool/fix_corrupted_nef_win.zip
Unpack the zip archive into an empty folder
Copy all files you want to repair into this folder with the fix_corrupted_nef.exe application in it
Select all .NEF files and drag & drop the files with the mouse onto the application icon
Choose 12 bit
You will get a new folder named »fixed« containing the repaired files

For me, the repaired files look like normal RAWs. I do not know how many files you can transform at once but three worked fine :wink: .

Although this is not what this Phil Harvey’s excellent tool was designed to do, it is always worth trying with broken NEF files. It often creates nice surprises.

@Narayan I once experienced a corrupt SD card after camping and hiking up mountains in Italy’s Dolomites region. The SD card cost just ~35EUR, but the trip and the sweat were essentially priceless. I used http://www.cgsecurity.org/wiki/TestDisk to recover what could be recovered. Next, I used Adobe DNG Converter in batch mode to convert all the recovered files (Pentax PEF format) to DNG. I did that to filter out the hopelessly corrupt files from the usable ones. You could try that.

Never use the partition which contains the corrupted or deleted files! Don’t boot from it, don’t use it. Recover to a separate partition, preferably to separate disk if dealing with corruption (recovering to a separate partition on the same disk should be safe if dealing with deleted files, but dangerous when dealing with corrupted files/partitions/volumes/disks).

Hi everyone, sorry for the late reply, but I wanted to thank you all for your efforts! I went with Thomas Do’s suggested tool, and this worked fine for me. Thank you!

I decided to get rid of the MacBook and the sd card, to make sure this doesn’t happen anymore.

2 Likes