Last active
November 17, 2020 13:52
-
-
Save mylamour/92eb7eeb786521ad144b328d2ad88632 to your computer and use it in GitHub Desktop.
convert NEF file to jpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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