Recovering corrupted .nef files

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

I have corrupted NEF files from a Nikon D7500 I am desperately trying to open. It looks like your pre-script won’t work with this model camera. Do you have anything that would work? I would be SO SO grateful. I am a total noob when it comes to this kind of data recovery. :sob:

@ClaytonJW Welcome to the forum! Have you read the whole thread? There is lots of useful info.

1. As I said above, the most important thing is to stop using the corrupted card or disk and make a bit-by-bit copy of it into an image on a separate piece of hardware. That way you would remove the chance for further corruption due to failing hardware.

2. If you don’t mind, sharing a raw file here (just drag and drop into the editor) is probably the best way to show us the sort of problem you are encountering. It is up to you of course, but it would certainly help us find a solution to your issue, which may potentially be very simple.

Adobe DNG Converter worked for me for corrupted files (accidentally deleted and then recovered from an SD card).
http://rawpedia.rawtherapee.com/How_to_convert_raw_formats_to_DNG

Hi everyone! I’m new here, and trying to recover some corrupt .NEF files. The NEF files are files that were pulled from a Seagate external drive that was accidentally wiped. I got a lot of stuff back, but have these weird .NEF files that won’t open in lightroom or preview in Finder. (I’m using Mac OS 10.14 Mojave). The files are from a D800.

I’ve already tried the remedy listed above at the website http://owl.phy.queensu.ca/~phil/exiftool/fix_corrupted_nef_win.zip. It says it completes successfully, but the copied file is just another NEF that won’t open.

I’ve also tried the Adobe DNG Converter, but out of ~900 files, only two successfully converted.

Is there any hope or another solution to hopefully get these files back? Luckily all client work was not lost, but sadly these are all personal photos from this past summer’s travels with my kiddo. We went on a couple adventures together to celebrate my being done with cancer treatments, and I would just love to still have the photos, although I’m starting to think I’ll just have to be happy with what I have. :confused: I recovered about 25% of them, but would love to get more, if at all possible. Thanks for all the above help that’s already been provided!