Skip to content

Instantly share code, notes, and snippets.

@mylamour
Last active November 17, 2020 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mylamour/92eb7eeb786521ad144b328d2ad88632 to your computer and use it in GitHub Desktop.
Save mylamour/92eb7eeb786521ad144b328d2ad88632 to your computer and use it in GitHub Desktop.
convert NEF file to jpeg
import os
import time
import rawpy
import click
import imageio
import argparse
from concurrent.futures import ProcessPoolExecutor
def neftojpeg(path):
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
jpegpath = path.lower().replace("nef","jpeg")
if not os.path.exists(jpegpath):
imageio.imsave(jpegpath, rgb)
def process(nefs):
with ProcessPoolExecutor() as executor:
executor.map(neftojpeg, nefs)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dir", help="NEF directory")
parser.add_argument("-f", "--file", help="NEF file")
args = parser.parse_args()
if args.file and os.path.isfile(args.file):
neftojpeg(args.file)
else:
directory = args.dir
if os.path.exists(directory) and os.path.isdir(directory):
nefs = []
for f in os.listdir(directory):
if f.lower().endswith(".nef"):
nefs.append(os.path.join(directory, f))
process(nefs)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment