Batch extract RAW files from DNGs with original file name

Started by StarGeek, October 30, 2021, 05:08:09 PM

Previous topic - Next topic

StarGeek

I was trying to think of a way to batch extract RAW files from DNG files and use the original filename.  The only thing I came up with was a two step solution using a temp file.

First, run this
exiftool -ext DNG -p "#[IF] $OriginalRawFileName $OriginalRawImage" -p "#[BODY] -b" -p "#[BODY] -W" -p "#[BODY] %d$OriginalRawFileName" -p "#[BODY] -OriginalRawImage" -p "#[BODY] $Directory/$FileName" -p "#[BODY] -execute" /path/to/files/ >temp.txt

Then, you could run
exiftool -@ temp.txt

The first step creates a arg file (see -@ (Argfile) option) which gives the commands to extract the embedded original RAW files with the original name into the same directory as the DNG

Some further thought, the output from the first could be piped into the second.  Seemed to work with my quick test
exiftool -ext DNG -p "#[IF] $OriginalRawFileName $OriginalRawImage" -p "#[BODY] -b" -p "#[BODY] -W" -p "#[BODY] %d$OriginalRawFileName" -p "#[BODY] -OriginalRawImage" -p "#[BODY] $Directory/$FileName" -p "#[BODY] -execute" /path/to/files/ | exiftool -@ -
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

I was thinking about this myself.  Your way is very smart, but tricky.  It would have been better if I had a feature to embed tag names in the -W string, but doing this would take some work.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Phil Harvey on October 30, 2021, 05:27:48 PM
It would have been better if I had a feature to embed tag names in the -W string, but doing this would take some work.

That's what I figured.  And I don't recall any time where it couldn't be worked around.

For most people, a simple -W %d%f.nef or something similar would work.  But it got me thinking about the edge case of if there wrere different embedded RAW file types.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Quote from: StarGeek on October 30, 2021, 05:45:22 PM
or most people, a simple -W %d%f.nef or something similar would work.  But it got me thinking about the edge case of if there wrere different embedded RAW file types.

You can use %s for the suggested extension of the file, and it should work for all raw files like this (it actually peeks at the extension of OriginalRawFileName to do this -- actually, maybe just adding a %o for the original raw file name would be enough since this is the most common use case).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: Phil Harvey on October 30, 2021, 09:42:49 PM
You can use %s for the suggested extension of the file, and it should work for all raw files like this

I tried that before making this and the resulting file had a .dat extension.  At least for the embedded .orf file.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

If the OriginalRawFileName tag existed then this shouldn't happen.  If it did, we have a bug.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Here's the command I used.  The file saved is named PB290252.dat.
exiftool -W %d%f.%s -b -OriginalRawImage Y:\!temp\ccccc\d\a\PB290252.dng

As the image is not mine, I'm sending you a link..
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Ah, great!  Yes, bug.  Thanks!  This will be fixed in 12.35.  I will also add a %o format code to represent OriginalRawFileName.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Actually, I changed my mind.  The uppercase format codes are for the -w option only, and are documented in that section.  The extra -W format codes don't have uppercase equivalents, and I think I want to add %o to these.  Also, if necessary, removing the extension can easily be done with %-.4o.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).