Rename raw image plus sidecar jpeg plus darktable xmp

Started by metadata, August 13, 2018, 04:24:32 PM

Previous topic - Next topic

metadata

Hi,

I'm trying to rename my raw (RW2) images, their sidecar jpegs and xmp files—created by darktable—in one single run.
The files are named like this:

P1040235.JPG
P1040235.RW2
P1040235.RW2.xmp


After reading https://exiftool.org/forum/index.php?topic=1423.0 and https://exiftool.org/forum/index.php?topic=1672.0 I got:

exiftool -V -d "%Y-%m-%d-Additional-Description-%Hh%Mm%S" '-FileName<${DateTimeOriginal}%-.2nc.%le' .

This works fine for the RW2 and JPEGs. Unfortunately, the darktable XMP don't have a DateTimeOriginal (or another datetime field which represent the date the photo was taken).
So, I tried:

exiftool -V -tagsfromfile %f.RW2 -d "%Y-%m-%d-Additional-Description-%Hh%Mm%S" '-FileName<${DateTimeOriginal}%-.2nc.%le' -fileOrder -filename .
======== ./P1040235.RW2.xmp
Setting new values from P1040235.RW2.RW2
Warning: Error opening file - P1040235.RW2.RW2
Nothing changed in ./P1040235.RW2.xmp
======== ./P1040235.RW2
Setting new values from P1040235.RW2
'./P1040235.RW2' --> './2018-08-10-Additional-Description-21h20m09-01.rw2'
======== ./P1040235.JPG
Setting new values from P1040235.RW2
Warning: Error opening file - P1040235.RW2
Nothing changed in ./P1040235.JPG
    1 directories scanned
    1 image files updated
    2 image files unchanged


This fails for the XMP because darktable names the XMP files like %f.%e.xmp where %f is the filename and %e is the extension of the RW2 file. So, P1040235.RW2
becomes P1040235.RW2.xmp and exiftool looks for P1040235.RW2.RW2 when trying to process the XMP.

So, I tried:

exiftool -V -tagsfromfile %f -d "%Y-%m-%d-Additional-Description-%Hh%Mm%S" '-FileName<${DateTimeOriginal}%-.2nc.%le' -fileOrder -filename .
======== ./P1040235.RW2.xmp
Setting new values from P1040235.RW2
'./P1040235.RW2.xmp' --> './2018-08-10-Additional-Description-21h20m09-01.xmp'
======== ./P1040235.RW2
Setting new values from P1040235
Warning: Error opening file - P1040235
Nothing changed in ./P1040235.RW2
======== ./P1040235.JPG
Setting new values from P1040235
Warning: Error opening file - P1040235
Nothing changed in ./P1040235.JPG
    1 directories scanned
    1 image files updated
    2 image files unchanged


This matches only the XMP file but messes up the "doubled" extension ( %f.xmp instead of %f.rw2.xmp).

Is there a way to rename the rw2, jpeg and xmp in one run—or is the %f.rw2.xmp extension a showstopper?

Regards

Phil Harvey

What about something like this?:  (I don't have time to try it now, but something along these lines may work)

exiftool -V -d "%Y-%m-%d-Additional-Description-%Hh%Mm%S" -tagsfromfile %f.RW2 '-FileName<${DateTimeOriginal}%-.2nc.%le' -tagsfromfile %-.4f.RW2 '-FileName<${DateTimeOriginal}%-.2nc.%le' -fileOrder -filename .

This should find the .RW2 even if it has an extra extension in the source file name.  Of course, the extra extension will be removed in the renaming -- I hope this is what you want.

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

jeepei

Hello,

I had same problem for renaming files from Darktable:


IMG_3441.CR2
IMG_3441.CR2.xmp
IMG_3441.JPG
IMG_3441.JPG.xmp


into this:

2018-07-23_20h19m18_IMG_3441.CR2
2018-07-23_20h19m18_IMG_3441.CR2.xmp
2018-07-23_20h19m18_IMG_3441.JPG
2018-07-23_20h19m18_IMG_3441.JPG.xmp


Thanks to you, works great with these lines:


exiftool -V -d "%Y-%m-%d_%Hh%Mm%S_%f" -tagsfromfile %f.CR2 '-FileName<${DateTimeOriginal}.%e' -tagsfromfile %-.4f.CR2 '-FileName<${DateTimeOriginal}.%e' -fileOrder -filename .



mdrmike

Yes, this can work to rename darktable xmp paired sidecar files. I have collections of both Canon CR2 and Sony ARW raw files. But I prefer a more readable date format and only add a unique file counter (%C) when needed (photos taken during the same second, which is typical for camera bursts or bracketing).  To do this, I combined a bit of Phil Harveys answer with jeepei's to support my prefferred format. This works for Sony ARW (first processing paired JPG and Darktable xmp sidecar files):

exiftool -verbose -dateFormat "%Y-%m-%d____%H_%M_%S" -tagsfromfile %f.ARW '-FileName<${DateTimeOriginal}%+c.%e'  -tagsfromfile %-.4f.ARW '-FileName<${DateTimeOriginal}%+c.ARW.%e' -fileOrder -filename .



But Wait ... ???

After using this solution a couple times, I realized reversing input by filename to rename, and using %C to ensure unique filenames (such as in the OP {DateTimeOriginal}%-.2nc and in Phil Harveys suggestion); the result can cause camera "bursts" to be numbered in reverse chronological order.
::)


Example
exiftool -V -d "%Y-%m-%d-Additional-Description-%Hh%Mm%S" -tagsfromfile %f.ARW '-FileName<${DateTimeOriginal}%-.4nc.%e' -tagsfromfile %-.4f.ARW '-FileName<${DateTimeOriginal}%-.4nc.%e' -fileOrder -filename .

Output
DSC00004.ARW.xmp   renamed >>  2021-01-31-Additional-Description--21h20m09-0001.ARW.xmp   
DSC00004.ARW       renamed >>  2021-01-31-Additional-Description--21h20m09-0001.ARW
DSC00003.ARW.xmp   renamed >>  2021-01-31-Additional-Description--21h20m09-0002.ARW.xmp
DSC00003.ARW       renamed >>  2021-01-31-Additional-Description--21h20m09-0002.ARW
DSC00002.ARW.xmp   renamed >>  2021-01-31-Additional-Description--21h20m10-0003.ARW.xmp
DSC00002.ARW       renamed >>  2021-01-31-Additional-Description--21h20m10-0003.ARW
DSC00001.ARW.xmp   renamed >>  2021-01-31-Additional-Description--21h20m10-0004.ARW.xmp
DSC00001.ARW       renamed >>  2021-01-31-Additional-Description--21h20m10-0004.ARW


Explanation
Why does this happen? Since criteria to name file is based on "the same date/time" but the last photos of the burst are encountered first (and therefore %C indexes in reverse). This is compounded when burst sequences cross multiple seconds. I found this by accident, when I had a copy of files and started to sync with my external USB. I use RSYNC to do a checksum, and it found my "originally renamed" files with sequences no longer matched... and by previewing the photos I was able to determine what happened.


Helpful notes for others (and future me):
Solution
Unless exiftool has a better way of handling paired files since this was suggested, the more complete solution would be to use multiple statements to process files in normal ascending sequence, and to process dependent paired files first so we can find the original raw file with tags.

Here's my current solution to process SONY ARW darktable and JPG paired files. Note having -fileOrder filename ensures acending input sequence, I don't think its required, but I haven't bothered to test.  YMMV


exiftool -ext xmp -verbose -dateFormat "%Y-%m-%d____%H_%M_%S" -tagsfromfile %-.4f.ARW '-FileName<${DateTimeOriginal}%+c.ARW.%e' -fileOrder filename . 
exiftool -ext JPG -verbose -dateFormat "%Y-%m-%d____%H_%M_%S" -tagsfromfile    %f.ARW '-FileName<${DateTimeOriginal}%+c.%e'     -fileOrder filename .
exiftool -ext ARW -verbose -dateFormat "%Y-%m-%d____%H_%M_%S" '-FileName<${DateTimeOriginal}%+c.%e' -fileOrder filename .