Variable for frame number for renaming on import

When importing images into darktable, I am trying to replicate the naming convention I’ve been using for years in Photo Mechanic:

{datesort}_{frame4}_{timesort}

The closest I’ve got in darktable is:

$(EXIF_YEAR)$(EXIF_MONTH)$(EXIF_DAY)_${SEQUENCE}_$(EXIF_HOUR)$(EXIF_MINUTE)$(EXIF_SECOND)

But ${SEQUENCE} isn’t quite what I want… this is the sequence number within the import job (starting from 0000). What I want is the original frame number from the camera reel. This frame number is in ${FILE_NAME} but ideally I don’t want the redundant part of it, i.e. I don’t want DSC_5798 but only 5798.

Any way?

I don’t think we have that variable. I’m not even sure it is a variable within the metadata. Some cameras do have a cycle count in the metadata. What’s available via exiv2 in your raw file?

@g-man thanks for the reply. This is apparently available (Nikon D800):

# exiv2 -pa DSC_5798.NEF | grep '5798'
Exif.NikonFi.FileNumber                      Short       1  5798

With a LUA script? Perhaps a clue?

Maybe via a LUA script to read the NikonFi

Of course, it would also be possible to extract the frame number from the file name using something like a regexp ^DSC_(\d+)\.NEF$… not sure what is possible with scripting but I’ll check it out.

There are ways to manipulate darktables variables like ${FILE_NAME}. Things like
${FILE_NAME:4:4} or ${FILE_NAME#DSC_}. See the full description in the manual.
Though I’ve never used those options, let alone during import…

2 Likes

For my curiosity, how is that number useful in the filename?

So I think you would be able to use string subst feature of the variables …following on what @rvietor suggests…

I don’t do it for export but here I shared how I export my jpg edits in a way that automatically names them to match the raw files but it creates a parallel set of folders one with the raw files and xmp and one with only the edited exports…makes it easy to scroll through and view them… and it keeps the same file structure in both…

Basically you specify the variable, then a “/” search pattern, “/” what to replace that with…

You might be able to work that out to give you what you need on import…

https://docs.darktable.org/usermanual/4.6/en/special-topics/variables/#string-substitution

Edit it might even be simpler…

If your files are all DSC_(framenumber)

then this one might work…

image

Just remove the DSC_

1 Like

Thanks @priort and @rvietor. I hadn’t spotted those string substitution possibilities because I was looking in the import part of the docs, where that isn’t mentioned.

I can confirm that ${FILE_NAME:4:4} and ${FILE_NAME#DSC_} both work.

For completeness, I’m curious whether this could also be extracted directly from the EXIF without any scripting. From the linked docs page above I see that you can specify e.g. $(EXIF.FOCAL.LENGTH.EQUIV), so it would be neat if you could also specify any custom EXIF element, like my Exif.NikonFi.FileNumber… doesn’t seem to work but it would be nice if it did.

1 Like

Good question. It’s not particularly useful but it’s just following my general approach of not wanting to lose anything from the original (other than something useless like DSC_). I know the full file name is preserved in the metadata (and is in the Nikon-specific EXIF), but I just like to keep the same info that was in the original file name… in the new file name.