Geeks With Blogs
The Right Tempo A blog by Felipe M. G. Ceotto

About a month and a half ago I had a good friend visiting us for almost a month. Being also a photograph enthusiast, and one with a nervous finger, he took just over 4 thousand photos with his Nikon D5000. Of course we needed to download the files from his camera and free his SD card often, and we did that on my home computer, which is where I usually do the same with the photos taken with my Nikon D40. At the time he did not have his laptop with him and since I would want a copy of his photos as well, transferring them to my computer seemed only logical, I have a good system, backups in place, the whole shebang.

So it became common practice during that month, we would download the files to my computer, deleting the originals from his camera. To do that, instead of using the operating system to simply copy the files, I was using the software that came with my Nikon D40, that is, Nikon Picture Project 1.7 and Nikon Transfer, because of its renaming and auto-rotating option. I had never updated the software to Nikon ViewNX and the newer Nikon Transfer because the older one had always worked quite well. Little did I know that the older software was ruining some of my friend’s photos.

Because my friend took so many photos we did not go through a lot of them immediately, we were just downloading them, and only after he had left we found out that all his photos that were supposed to be in portrait orientation were corrupted. The preview was there, the thumbnail was there, but Photoshop Lightroom wouldn’t open them and despite having the latest Nikon RAW Codec installed, none of the viewing software we used, like Picasa Photo Viewer or Windows Photo Gallery would be able to show the files correctly.

After trying a couple of things like converting the files to DNG with Adobe DNG Converter and trying to open the files with other software, I had decided to contact Nikon and ask for help, while also asking for help on Photo.Net. I described the problem in detail and to Nikon I actually sent them one of the problematic photos, and the first answer I got from Nikon was that they were able to open the photo with their latest version of ViewNX and that I should download that. I did, and yes, I could view the file, but I could not export the file to anything, therefore I could not process the file or open it with any other software. Fiddling with ViewNX a bit I found out that what I was looking at was the embedded JPEG file inside the NEF file, not the actual RAW data, and selecting the option to view the actual RAW data in ViewNX rendered me a blank photo.

I replied that to Nikon and continued with my own investigations. In the meantime I got a lot of replies from Photo.Net but none that really solved the problem, although it was a lot of good advice that will help me in the future. We had a hunch that the problem was not with the image itself, but with its metadata, based on the fact that it is pretty much just metadata that is changes with the auto-rotate option, which was the option that most probably ruined the files since only portrait-oriented files were corrupt. So I started to play with the file’s metadata using a great tool: ExifTool by Phil Harvey.

To start I removed all metadata from the file, which didn’t work since RAW files do need some basic metadata to be opened, unlike JPEG files. That gave me another idea, so I asked my friend to take a portrait-oriented photo of a white wall (a gray card would have been better) with his Nikon D5000 and send me the RAW file. With that file in hands, I extracted all the metadata from it and replaced the metadata of one of the corrupt files with that. Voilà, I was able to open the corrupt file with Lightroom, but I still had some problems: the embedded JPEG of the corrupt file was substituted as well, meaning the thumbnail of that file was a white wall, and all other useful metadata, like aperture, shutter speed, ISO, date and time of exposure, etc. was also substituted with that of the white wall photo.

I informed these results to Nikon hoping that this would prove to them that the problem was a metadata problem only and that they would be able to narrow down on that and provide me with information on which metadata had the problem and how to correct it. I had also determined that it wasn’t one of the standard metadata (by substituting only that part and trying to open the file, which failed), but one of Nikon’s custom, encrypted, binary information. My hopes were up for a while but Nikon quickly replied just affirming again that Picture Project would have caused the issue with that RAW file, that I should use ViewNX to do that and that to access the original metadata from the corrupt file I should download them from the SD card again using ViewNX. Finally they said, and I quote, “unfortunately if you have deleted the images from your card the data is lost”, so they could not do anything else for the matter.

I was quite disappointed with Nikon for that, but I proceeded with my quest, this time writing a script that would do the following:

  1. Extract the embedded JPEG from the corrupt RAW files
  2. Save the original non-Nikon-specific metadata from the corrupt RAW files to XMP files
  3. Overwrite all metadata of the corrupt RAW files with metadata from the good, “white wall” file
  4. Restore the original non-Nikon-specific metadata from the XMP files to the once-corrupt RAW files
  5. Restore the embedded JPEG to the once-corrupt RAW files

I am pleased to say that this solution worked quite well and both me and my friend are quite happy with it. Something was lost still, like the “as shot” white balance, but nothing that can’t be adjusted with Lightroom afterwards.

Download the script here. Use it at your own risk, and please be very careful when using it, it will modify your RAW files, so please back them up first. To run this script you need to have a folder that contains only your corrupt NEF files, a good NEF file with a photo of a white wall or a gray card called GOODFILE.NEF, this script, and the ExifTool executable needs to be on your path.

Thank you for everybody at Photo.Net who gave this problem a shot!

Posted on Monday, July 12, 2010 11:46 AM Photography | Back to top

Comments on this post: Corrupted Nikon RAW (NEF) Files

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
I have issues to with the Nikon Raw files not opening.
Sent requests for assistance and will forward them to Japan if required.

This may become just an exercise in entertainement.

I do not have the skill set to use Adobe material, but I do try using other software and can do work arounds etc. for many computer issues.

I borrowed this Nikon D40, at least this will be one company to avoid.

Your information helps place this camer company where it belongs Hahaha!


Left by L L on Oct 10, 2010 11:00 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Thanks for the script. While it didn't repair my corrupt NEF file (must be a card error), I modified the script so it wouldn't delete the JPG. That was all I needed and will keep my client happy I didn't lose her image!
Thanks again.
Left by Will Prentice on Sep 01, 2011 11:09 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
I downloaded your script and obtained the Exiftool from the site you recommended. However, although I created the folders and files you instructed I do not see where I am getting the JPEG files. When I drag and drop the corrupted NEF files into the Exiftool icon I see the metadata that is produced, but when I run the Nikon Command Script from your site I get a quick flash of a black box and then nothing.

Is there something else I need to do? 60% of the NEF files from a wedding we shot are horribly corrupted and unreadable. The sidecar thumbnails seem fine though.

Any ideas?

Left by Adam Smith on Oct 10, 2011 9:00 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
WOW, I just had a similar issue. My computer crashed and I had to do a factory reest on it, before that was done I saved all of my files from the hard drive to an external. Everything looked good.. All of the files were transfered over successfully. But one particular gallery is now showing roughly 200 photos as corrupt. And I think it's possible that the metadata is incorrect, because as you mentioned I was able to view a preview of the photo initially in LR, but then when i tried to import the files they were not the correct one.
I'm hoping what you have will help me. As the photos I took and the only gallery i had not had a chance to back up in a second location is affected. I will definitely write back with any updates on the script... Cross your fingers!
Left by Nohemi on Nov 28, 2011 11:07 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Thanks for this post. I have this probleme i think. I tried your solution but nothing happens.
I have a directory with the corrupted file ; exiftoof.exe and a nef named GOOGFILE.NEF. I tried to do something with exiftool but i don't understand how it work.
Maybe it's the probleme.

Thank for yopur help
Left by Greg mistral on May 12, 2012 10:12 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Ok, I am on Mac and having issues executing the file.
This is what I get
Last login: Thu May 31 11:33:27 on ttys000
Robs-Mac-Pro-3:~ TPG$ /Volumes/Master/recover/correctNikonProblem.cmd ; exit;
/Volumes/Master/recover/correctNikonProblem.cmd: line 1: @echo: command not found
/Volumes/Master/recover/correctNikonProblem.cmd: line 12: syntax error near unexpected token `('
/Volumes/Master/recover/correctNikonProblem.cmd: line 12: `for %%E in (*.NEF) do'if "%%E" neq "GOODFILE.NEF" exiftool -b -jpgfromraw -w jpg %%E > NUL

[Process completed]

On the mac exiftool is already installed.... Help would be appreciated
Left by Rob on May 31, 2012 4:31 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Hello there, Rob.
Unfortunately the cmd file is a Windows batch file, so it won't work with Mac.
If you have any knowledge of shell scripts for MacOS X, please feel free to take a look at how I've written this Windows batch and translate it into a shell script for Mac, it shouldn't be difficult.
Left by Felipe on May 31, 2012 9:34 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
I was wondering if any one was able to translate the script into a OSX executable file. I have 9K NEF files that are corrupted including all of my photos of my two sons since they were born to 3 years of age. I REALLY need to figure out how to fix these photos. Any help would be greatly appreciated.

Thank you!
Left by Christian Jimenez on Jul 27, 2012 12:28 AM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Thankyou thankyou thankyou thankyou.

See above

See above the see above.

2 folders of corrupt nef files ( including first trip the the show of my twins ) saved.
Left by Wolf on Nov 05, 2012 11:42 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
hi, as instructed, i have the nef's and the script and the exif tool in a folder...when i execute the meta script, it process's meta data...when i run your script, nothing happens...any ideas?
Left by Bob on Dec 06, 2012 4:37 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
It appears the author of this post is not around anymore :(
Left by Christian on Dec 26, 2012 4:37 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
I have problems with SD card. The ball hit the camera on tripod and fell down. Last cca 30 pictures are corrupted and not readable. All pictures are NEF format.
With script above I get from corrupted images an jpeg image size of 120x90 pixels and no original, but from goodfiles I get original size of JPEG.

Any idea how to get original size jped from corrupted images?

Left by Borut on Jan 02, 2013 8:47 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
i guess my NEF are corrupted due to either the thumbnail codec or lightroom. now, i cant access a number of NEF. unfortunately, i am using D90. The script that u share does not seem to support this model. can we discuss how i can modify one so that i can fix my NEF?
Left by Mike on May 24, 2013 6:41 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
I see this is an old post, but it looks like the last resource I can use to try to fix some corrupt files. I admit I am not 100% tech saavy and I cannot figure out how to setup ExifTool's PATH for this. Or at least I think that is the issue. Can anyone help me from here?
Left by Ally on May 25, 2013 12:01 AM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
This worked perfectly. Almost lost a whole wedding!
Left by Nathan on Jun 05, 2013 8:05 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
@Nathan - how did you manage to get it to work?
Left by rob on Jun 23, 2013 6:56 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Hi, this seems like what I need. However I shoot canon, and I am on a mac. If you Felipe, or anyone on here can selvedge these files i will be willing to compensate you for your time.

Left by chris on Sep 11, 2013 9:33 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Just successfully fixed D800E NEF file error "Could not complete your request because an unexpected end-of-file was encountered in Photoshop CS6 (Windows 8.1 64bit). Many thanks!!
Left by Jundar on Mar 07, 2014 2:12 AM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
ok, I don´t know If someone else had the same problem. I had a problem with a disk, but could recover the files. I lost some of them, just 3 o 4 nef files. The rest imported on Lightroom, but there were a lot of files that could´t be modified on the deveolp mode. I could see them, but not could change anything. "an unexpected end of file occured" was the message. I Could not export or open on PS either. So I opened on Photo Mechanic, save as JPG, and thats all.

Left by max on Apr 28, 2014 5:43 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Help please !!!
does not want to open
Left by Dj Nick on Sep 02, 2014 5:37 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Brilliant, jackass. You need to say "windows" or "mac" before going into a discourse of why this is so fucking awesome. Thanks for wasting my time, jackhole.
Left by Surfer on Mar 06, 2015 7:17 PM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Thank you! I have some sucess recovering some files from my Nikon D5100 card, a child birthday registry save thanks to you. You got my respect!
Left by JUVENCIO on May 31, 2016 2:54 AM

# re: Corrupted Nikon RAW (NEF) Files
Requesting Gravatar...
Images were created on D750 and D500. I ran the script as instructed on MAC and Windows unit. I got the same error message listed below. Any assistance would be deeply appreciated.

Thank you

Error: Not a characteristic corrupted NEF - D:/5069/_DSC8904.NEF
======== D:/5069/_DSC8905.NEF [208/210]
Error: Not a characteristic corrupted NEF - D:/5069/_DSC8905.NEF
======== D:/5069/_DSC8906.NEF [209/210]
Left by Gary on Dec 29, 2016 1:25 AM

Your comment:
 (will show your gravatar)

Copyright © Felipe Martino Gagno Ceotto | Powered by: