The Computer Oracle

How do I batch convert thousands of NEFs to JPEGs?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island Looping

--

Chapters
00:00 How Do I Batch Convert Thousands Of Nefs To Jpegs?
00:34 Answer 1 Score 28
01:56 Answer 2 Score 11
02:22 Accepted Answer Score 10
03:13 Answer 4 Score 3
03:30 Answer 5 Score 2
03:42 Thank you

--

Full question
https://superuser.com/questions/577643/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#batch #jpeg #imageconversion #cameraraw

#avk47



ANSWER 1

Score 28


One solution, on Ubuntu, would be to use dcraw to convert NEF to PBM, and pnmtopng to convert PBM to png. So, open a terminal and run these commands:

sudo apt-get install netpbm dcraw

I don't have any .NEF images to test this, but according to this page, you can do:

Convert all NEF images to PNG:

dcraw -c -w input.NEF | pnmtopng > output.png

To convert an entire directory:

for filename in *.NEF ; do dcraw -c -w "$filename" | pnmtopng > "$filename.png" ; done

Probably the best tool around for all your batch image processing needs, however, is ImageMagick. It's free, open source, cross platform and can do just about everything you can think of including resizing, cropping, managing transparancy, montage and converting between most image formats under the sun. It would have been my first choice, but I found some (older) posts claiming that it did not work with NEF. Still, their website says it does, so you should try it out and in any case, it is really worth learning. Install it on Ubuntu with:

sudo apt-get install imagemagick

To convert a single .NEF:

convert foo.NEF foo.jpg

To convert all .NEF files in the current directory (will overwrite the originals):

mogrify -format jpg *.NEF

To do the same but keeping the original files, run convert in a loop:

for img in *.NEF; do convert "$img" "$img.jpg"; done



ANSWER 2

Score 11


If you do end up using ImageMagick, then I recommend using xargs if you've actually got thousands of images to convert rather than using a for loop. That way, you can easily bump up the parallelism:

# Runs these conversions serially
ls *.NEF | sed 's#.NEF##' | xargs -I^ convert ^.NEF ^.jpg

# Runs these conversions with 8 different processes
ls *.NEF | sed 's#.NEF##' | xargs -P8 -I^ convert ^.NEF ^.jpg



ACCEPTED ANSWER

Score 10


Another great free tool is IrfanView that when combined with plugins can Batch convert from almost any format to JPG.

Q: Can I use IrfanView on Linux?

A: Yes. There is no native-Linux version of IrfanView. However, you can use IrfanView in conjunction with Linux programs like WINE, Windows Linux emulators and Linux-based virtual machines. Take the ZIP version of IrfanView and unzip it or copy your existing Windows IrfanView folder to Linux. This is easier because the installer may need additional Windows DLLs to run.

If you want a software that is more OS independent then I would recommend UFRaw. Use it either on its own or in conjunction with Gimp




ANSWER 4

Score 3


Using GNU Parallel:

parallel convert {} {.}.jpg ::: *NEF

Deals correctly with filenames containing ', " and space.




ANSWER 5

Score 2


You can use NEFtoJPG. Its free and can do batch processing.