Can I copy EXIF tags from RAW files to preview files in one command.?

Started by PatD, April 05, 2024, 04:03:50 PM

Previous topic - Next topic

PatD

This works from my C# program. It also works if I specify PreviewImage, OtherImage or ThumbnailImage instead, depending on the source of the RAW file. It would save accessing the raw files twice if I could have the EXIF tags copied to the preview file when it is extracted. I tried adding "-tagsfromfile" but that caused the command to fail with file not found errors.


>exiftool -preview:JpgFromRaw -a -b -W C:\Users\patjd\AppData\Local\Temp\AAATmp_638479286012020487/%f_%t%-c.%s C:\Temp\Raw\Raw191\

Phil Harvey

This really needs to be done in 2 commands.

Maybe this is a feature to add in the future...

- 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 ($).

PatD

That would be nice. I hadn't realized until I did Preview:all that RAW files contained multiple preview images, some at very usable resolution. I'm updating a program I wrote years ago to help me preview the files on an SD card and transfer the RAW copies that were worth processing to my computer. When you come home from Magee Marsh with 2000 photos, you want to sort through them fast before importing them into Lightroom, DXO or whatever. It depended on shooting RAW + JPG. I thought I'd update it so it could work with RAW files directly. Exiftool saved my day. I use Exiftool to extract the preview JPGs into a temp folder and show the user those images. Extracting actual RAW images is far slower.

Phil Harvey

I'm playing with a new feature that would allow you to do exactly what you want.  If all goes well then ExifTool 12.83 will have this ability (likely in the form of a new SetTags helper function for use in advanced-formatting expressions).

- 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 ($).

wywh

Quote from: PatD on April 05, 2024, 09:41:25 PM2000 photos, you want to sort through them fast before importing them into Lightroom

Thanks for pointing this out. I have the same "problem" -- my son shoots raw and he often brings hundreds of them from family occasions for me to sort out the best (usually less than 10%) for further editing. Extracting previews makes this step faster than slowly going through raws or exporting them as .jpg.

I did some clumsy tests and look forward for a more elegant solution where maybe only the best resolution is extracted. I also tested -tagsFromFile but was left wondering whether -All:All or just -All is better to let exiftool copy the metadata to the proper location from the raw to the .jpg (there is a recent dashcam .mp4 preview that v12.82 fixed in the mix).

exiftool -a -G1 -s -ee -Preview:All .
======== ./2023-0621-1601-48.cr3
[Canon]        ThumbnailImage                  : (Binary data 15640 bytes, use -b option to extract)
[Track1]        JpgFromRaw                      : (Binary data 1118752 bytes, use -b option to extract)
[QuickTime]    PreviewImage                    : (Binary data 229800 bytes, use -b option to extract)
======== ./2023-0210-1801-32.cr2
[IFD0]          PreviewImage                    : (Binary data 2587260 bytes, use -b option to extract)
[IFD1]          ThumbnailImage                  : (Binary data 15887 bytes, use -b option to extract)
======== ./2023-0614-1945-07.dng
[IFD0]          PreviewImage                    : (Binary data 8623 bytes, use -b option to extract)
[SubIFD1]      PreviewImage                    : (Binary data 277363 bytes, use -b option to extract)
======== ./REC20240331-124910-F0-890.mp4
[Track3]        PreviewImage                    : (Binary data 7410 bytes, use -b option to extract)

Some extract tests:

exiftool -a -ee -b '-Preview:*' -W '%f_%t%+.nc.%s' .

exiftool -a -ee -b -JpgFromRaw -W '%f_%t%+.nc.%s' .

exiftool -a -ee -b -JpgFromRaw -W '%f_%t%+.nc.%s' -PreviewImage -W '%f_%t%+.nc.%s' -ThumbnailImage -W '%f_%t%+.nc.%s' .

clumsy tagsFromFile test (number "13" must match the length of "_JpgFromRaw_1"):

exiftool -m -overwrite_original -tagsFromFile '%-.13f.cr3' -All '-FileCreateDate<ExifIFD:DateTimeOriginal' '-FileModifyDate<ExifIFD:DateTimeOriginal' *_JpgFromRaw_1.jpg


- Matti

Phil Harvey

I've got the helper function working nicely, and a command like this will work in 12.83:

exiftool -p "${previewimage;SetTags}" -b -w _preview.jpg DIR

Which is the same as using -tagsfromfile with -all.

Or you can add arguments to copy/write specific tags

exiftool -p "${previewimage;SetTags('all:all')}" -b -w _preview.jpg DIR

exiftool -p "${previewimage;SetTags('description<filename','title<A Preview of $filename')}" -b -w _preview.jpg DIR

exiftool -p "${previewimage;SetTags('all:all','imagedescription=test')}" -b -w _preview.jpg DIR

The SetTags arguments are the same as the command-line arguments for copying/writing tags, but without the leading dash.

- 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 ($).

PatD


wywh

That works otherwise OK in v12.83 but somehow the extracted .jpg is always upside down if tags are copied:

exiftool -p '${PreviewImage;SetTags}' -b -w _preview.jpg 2023-0621-1601-48.cr3
    1 output files created
exiftool -a -G1 -s -Orientation 2023-0621-1601-48*                         
======== 2023-0621-1601-48.cr3
[IFD0]          Orientation                     : Horizontal (normal)
======== 2023-0621-1601-48_preview.jpg
[IFD0]          Orientation                     : Rotate 180

Is it possible to extract the best resolution if there are many raw images in the mix?

For that .cr3 PreviewImage (1620x1080) is OK but there is also JpgFromRaw (5472x3648):

exiftool -a -G1 -s -Preview:All -ImageSize 2023-0621-1601-48_*
======== 2023-0621-1601-48_JpgFromRaw_1.jpg
[Composite]     ImageSize                       : 5472x3648
======== 2023-0621-1601-48_PreviewImage_1.jpg
[Composite]     ImageSize                       : 1620x1080
======== 2023-0621-1601-48_ThumbnailImage_1.jpg
[Composite]     ImageSize                       : 160x120

exiftool -a -G1 -s -Preview:All .                                                                     
======== ./2023-0614-1945-07.dng
[IFD0]          PreviewImage                    : (Binary data 8623 bytes, use -b option to extract)
[SubIFD1]       PreviewImage                    : (Binary data 277363 bytes, use -b option to extract)
======== ./2023-0210-1801-32.cr2
[IFD0]          PreviewImage                    : (Binary data 2587260 bytes, use -b option to extract)
[IFD1]          ThumbnailImage                  : (Binary data 15887 bytes, use -b option to extract)
======== ./2023-0621-1601-48.cr3
[Canon]         ThumbnailImage                  : (Binary data 15640 bytes, use -b option to extract)
[Track1]        JpgFromRaw                      : (Binary data 1118752 bytes, use -b option to extract)
[QuickTime]     PreviewImage                    : (Binary data 229800 bytes, use -b option to extract)

p.s. SetTags example command seems miss closing parenthesis:
SetTags [...] Arguments may be added to copy or set specific tags. Should be:
exiftool -p '${PreviewImage;SetTags("comment=test","title<filename")}' ...

- Matti

Phil Harvey

Hi Matti,

Interesting, thanks.  I'll fix the documentation and investigate the Orientation difference.

You can extract the largest image with the BigImage Composite tag from the sample config file.

- 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 ($).

Phil Harvey

OK.  I've solved the Orientation problem.  This will be fixed in 12.84.

The problem was that tags with print conversions were not handled properly.  To work around this with 12.83, I would recommend doing this: SetTags('all:all#').  I might recommend doing it this way anyway to keep the metadata in the same locations.

- 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 ($).

wywh

Thanks again. This works great and picks the best resolution preview with the .ExifTool_config file:

exiftool -config .ExifTool_config -p '${BigImage;SetTags("All:All#")}' -b -w _preview.jpg .
p.s. In macOS those normally invisible dot files (.ExifTool_config) can be handled easily by making them visible in the Finder via Shift-Command-. (that is period at the end). Repeat to revert to the default.

- Matti

PatD

Thanks for implementing this. Helps me a lot. The inverted images issue got w work-around posted pretty quickly, so thanks again.

I was trying to figure out how to get the best resolution preview when the folder being searched has files with different preview image sizes. My Sony A7CR gives me a JpgFromRaw which is full resolution whereas my Sony RX100 only gives a much smaller PreviewImage. I saw wywh's solution but, as a newbie with zero Perl knowledge, I have no idea how to create a .ExifTool_config file.

In reality, having a folder on an SD card with images from two different cameras is unlikely. If I am processing archived folders containing RAW images from two different cameras I can find work-arounds by detecting when the number of files created is less than the number in the source. If a rare case requires multiple passes, so be it.

Phil Harvey

Just download the example example config file -- this includes the Composite BigImage tag.

- 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 ($).

wywh

Quote from: PatD on April 20, 2024, 10:48:23 AMhow to create a .ExifTool_config file

I am also a newbie with config files. But if you want to use or modify that particular exiftool "example.config" file, you can grab it from https://exiftool.org/config.html or among https://github.com/exiftool/exiftool/tree/master/config_files. I prefer the latter (with "Download raw file") because the former very easily converts text to unusable HTML when saved from Safari (a workaround is to copy & paste to a text editor like BBEdit and save as text).

I wonder why those two pages above have the same example.config with some minor (?) differences?

Anyways, maybe the easiest way to get that latest "official" "example.config" file is to download it with the latest exiftool version from exiftool main page (currently Download Version 12.83). So download that, uncompress and grab Image-ExifTool-12.83.tar.gz/Image-ExifTool-12.83/config_files/example.config from it. Then put it into the same folder as the images, cd to that folder and just point exiftool to that with:

exiftool -config example.config -p '${BigImage;SetTags("All:All#")}' -b -w _preview.jpg .
...that is the quick 'n dirty way. A more kosher and permanent way is to put it to your home folder ~/ or exiftool application directory /usr/local/bin/exiftool and rename it as '.ExifTool_config'. macOS by default hides files beginning with a dot so that needs temporarily tweaking macOS Finder default to show and let the user rename it via Shift-Command- in the Finder. Or rename it via the Terminal command 'mv example.config .ExifTool_config'. Then the following command should work:

exiftool -p '${BigImage;SetTags("All:All#")}' -b -w _preview.jpg .
But if you handle just one type raw file such as .cr3, then you can just use a command that extracts the best resolution from it, like (v.12.84 might not need # to prevent upside down .jpg files anymore):

exiftool -p '${JpgFromRaw;SetTags("All:All#")}' -b -w _JpgFromRaw.jpg .
I hope this helps and chime in if I am missing something.

- Matti

Phil Harvey

Quote from: wywh on April 20, 2024, 12:51:22 PMI wonder why those two pages above have the same example.config with some minor (?) differences?

The html file was out-of-date and has been updated.  Thanks.

- 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 ($).