ExifTool Forum

ExifTool => Newbies => Topic started by: JobWellDone on December 21, 2022, 06:59:36 AM

Title: Organizing bracketed photos in folders.
Post by: JobWellDone on December 21, 2022, 06:59:36 AM
Hello i am trying to automate moving bracketed photos into folders of three images each.

This is EXIF data that is different between Bracketed and Single images in Sony NEX-5T camera.


EXIF TagShot 1Shot 2Shot 3Single Shot
Exposure Compensation0-2+20
Sequence Number123Single
Sequence Image Number1231
Sequence File Number1231
Release ModeExposure BracketingExposure BracketingExposure BracketingNormal
Release Mode 2Continuous - Exposure BracketingContinuous - Exposure BracketingContinuous - Exposure BracketingNormal
Release Mode 3BracketingBracketingBracketingNormal
Exposure ModeAuto bracketAuto bracketAuto bracketManual
Sequence Length3 shots3 shots3 shots1 shot

Separated bracketed photos from single ones with command (Linux)

exiftool -r -s -G1 -Directory="_Bracketed" -if '$ExposureMode eq "Auto bracket"' DIR
Could you help me write command for exiftool to move bracketed images into folders of three?

Timestamp of bracketed images is normally same second or +1 second so back in the day i created AutoHotkey script that groups based on time. Images that no more than 1 second apart get grouped into folders, but its inefficient, some images more than second apart (when camera buffer is full) and sometimes i press shutter by mistake too soon so two sequences are within second apart and get grouped to one folder.

Ideally need some IF condition to see weather image belongs to sequence before moving it to folder.
Title: Re: Organizing bracketed photos in folders.
Post by: Phil Harvey on December 21, 2022, 09:29:43 AM
How do you want to name these directories?  If the file numbers are sequential, one could imagine naming them according to the first image in the sequence:

exiftool -config first_file.config "-directory<firstfile" DIR

using this config file (also attached)

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        FirstFile => {
            Require => {
                0 => 'BaseName',
                1 => 'SequenceLength',
                2 => 'SequenceNumber',
            },
            ValueConv => q{
                return undef unless $val[1] > 1 and $val[0] =~ /(\d+)/;
                my $num = sprintf('%.*d', length($1), $1 - $val[2] + 1);
                $val[0] =~ s/(\d+)/$num/;
                return $val[0];
            },
        },
    },
);
%Image::ExifTool::UserDefined::Options = (
    RequestTags => 'BaseName',
);
1; #end

- Phil
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 22, 2022, 05:43:24 AM
Quote from: Phil Harvey on December 21, 2022, 09:29:43 AMHow do you want to name these directories?  If the file numbers are sequential, one could imagine naming them according to the first image in the sequence

Thank you so much Phill this works like charm and names folders just the way i need.

File names dont differ between bracketed and single images, they go like this:

_DSC0001.ARW
_DSC0002.ARW
_DSC0003.ARW
_DSC0004.ARW
_DSC0005.ARW
...
_DSC0088.ARW


Only minor distraction is warning displayed for images that are not part of sequence, if i am too lazy to separate them from bracketed photos prior to running your script.

Warning: No writable tags set from ARW/December 03 2022/_DSC0173.ARW
Title: Re: Organizing bracketed photos in folders.
Post by: Phil Harvey on December 22, 2022, 08:13:15 AM
You can add -q -q to the command to suppress warnings, but that will also drop the summary messages.

- Phil
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 22, 2022, 09:30:57 AM
Quote from: Phil Harvey on December 22, 2022, 08:13:15 AMYou can add -q -q to the command to suppress warnings, but that will also drop the summary messages.

- Phil

Thank you.

Quote from: Phil Harvey on December 21, 2022, 09:29:43 AM%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        FirstFile => {
            Require => {
                0 => 'BaseName',
                1 => 'SequenceLength',
                2 => 'SequenceNumber',
            },
            ValueConv => q{
                return undef unless $val[1] > 1 and $val[0] =~ /(\d+)/;
                my $num = sprintf('%.*d', length($1), $1 - $val[2] + 1);
                $val[0] =~ s/(\d+)/$num/;
                return $val[0];
            },
        },
    },
);
%Image::ExifTool::UserDefined::Options = (
    RequestTags => 'BaseName',
);
1; #end

Is there a way to modify config to also rename copied images adding value of tag Sequence Number to end of file?

From

_DSC0007.ARW
_DSC0008.ARW
_DSC0009.ARW

to

/_DSC0007/_DSC0007_SEQ1.ARW
/_DSC0007/_DSC0008_SEQ2.ARW
/_DSC0007/_DSC0009_SEQ3.ARW


Title: Re: Organizing bracketed photos in folders.
Post by: Phil Harvey on December 22, 2022, 09:45:42 AM
Use the same config file with this command:

exiftool -config first_file.config "-filename<$firstfile/%f_SEQ$sequencenumber.%e" DIR

(and read my signature if you aren't on Windows)

- Phil
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 22, 2022, 10:08:37 AM
Quote from: Phil Harvey on December 22, 2022, 09:45:42 AMUse the same config file with this command:

exiftool -config first_file.config "-filename<$firstfile/%f_SEQ$sequencenumber.%e" DIR

Wow that was easy, guess i need to read the manual more. Great tool Phil.
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 25, 2022, 05:28:41 AM
Marry christmas everyone!

I have made slight adjustment and whole script got broken.

exiftool -config first_file.config '-filename<${firstfile;$_=substr($_,0,13)}/%f.%e' DIR

======== /arw/06h-41m_(51s)_SEQ1.ARW [1/3]
'/arw/06h-41m_(51s)_SEQ1.ARW' --> '/arw/06h-41m_(51s)/06h-41m_(51s)_SEQ1.ARW'                          

======== /arw/06h-41m_(51s)_SEQ2.ARW [2/3]
'/arw/06h-41m_(51s)_SEQ2.ARW' --> '/arw/05h-41m_(51s)/06h-41m_(51s)_SEQ2.ARW'                          

======== /arw/06h-41m_(51s)_SEQ3.ARW [3/3]
'/arw/06h-41m_(51s)_SEQ3.ARW' --> '/arw/04h-41m_(51s)/06h-41m_(51s)_SEQ3.ARW'

    1 directories scanned
    3 directories created
    3 image files updated


Why in the world it makes filenames

06h-41m_(51s)
05h-41m_(51s)
04h-41m_(51s)

original filename for every file starts with "06h-41m_(51s)"?

Also manual page for substr() is nowhere to be found, so i had to just experiment with it perhaps i used it wrong?
Title: Re: Organizing bracketed photos in folders.
Post by: Phil Harvey on December 25, 2022, 07:53:21 AM
My config file assumes that the files are number sequentially and adjusts the file names back to the first number of the sequence.  If they aren't numbered sequentially, just don't use the config file and I think you'll get what you want.

- Phil
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 26, 2022, 01:11:56 AM
Hi Phil, pardon yesterday i got really frustrated spending several hours trying to make things work without any success.


Quote from: Phil Harvey on December 25, 2022, 07:53:21 AMMy config file assumes that the files are number sequentially and adjusts the file names back to the first number of the sequence.
Iinitially i did not notice difference in filenames after using your config guess because my files already come straight out of camera with sequence set in the same order as filename.

E.g.

_DSC0001.ARW
_DSC0002.ARW
_DSC0003.ARW - Sequence 1
_DSC0004.ARW - Sequence 2
_DSC0005.ARW - Sequence 3

Perhaps if you could mod the config to not rename files then it could work for any filenames.



Decided to make slight adjustment renaming them to something more meaningful like hour and minute and second photo was taken, so i run this script prior to executing config you provided.

exiftool  -d "%Hh-%Mm_(%Ss)" '-filename<${datetimeoriginal}_SEQ$sequencenumber.%e' -ext arw DIR

If i run it aftetwards folder names for sequences will not change.



If i run without your config e.g.

exiftool -d "%Hh-%Mm_(%Ss)" '-Directory<$datetimeoriginal' '-filename<$datetimeoriginal_SEQ$sequencenumber.%e' -ext arw DIR

then i can only stack if all three photos have same timestamp which is not always the case.

I tried to modify your original config but its beyond my understanding how it functions.

Quote from: Phil Harvey on December 21, 2022, 09:29:43 AM%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        FirstFile => {
            Require => {
                0 => 'BaseName',
                1 => 'SequenceLength',
                2 => 'SequenceNumber',
            },
            ValueConv => q{
                return undef unless $val[1] > 1 and $val[0] =~ /(\d+)/;
                my $num = sprintf('%.*d', length($1), $1 - $val[2] + 1);
                $val[0] =~ s/(\d+)/$num/;
                return $val[0];
            },
        },
    },
);
%Image::ExifTool::UserDefined::Options = (
    RequestTags => 'BaseName',
);
1; #end


Could you explain your config's inner mechanics, around this parts quoted below, what it does converted to plain english?

$val[0]=~ /(\d+)/;Is this regex, whats d+ for in /(\d+)/;?

my $num = sprintf('%.*d', length($1), $1 - $val[2] + 1);I know usage of sprintf() from php, but not sure of syntax used, is it perl?
What %.*d means and where $1 pointing to?

$val[0]=~ s/(\d+)/$num/;What this s/(\d+) does?

P.S. Is substr() a pearl function as well?

Title: Re: Organizing bracketed photos in folders.
Post by: Phil Harvey on December 26, 2022, 08:13:23 AM
Simply put: If you rename the files beforehand then my config file won't work.  The config file uses the number in the file name minus the SequenceNumber to determine the directory name.

You can rename the files at the same time, but now I'm guessing you may also tell me later that you want to rename the directories.  If you tell me what you want then I can help better.

sprintf() and substr() are Perl library functions.  s/// is the Perl substitution operator -- I don't have time explain how all this works, but you can google for "Perl regular expressions" to learn more about this.

- Phil
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 26, 2022, 08:02:16 PM
Quote from: Phil Harvey on December 26, 2022, 08:13:23 AMIf you tell me what you want then I can help better.

Final result i am trying to achive is to have folders and image named as -d "%Hh-%Mm_(%Ss)" from DateTimeOriginal


/06h-58m_(20s)/06h-58m_(20s)_SEQ1.arw
/06h-58m_(20s)/06h-58m_(20s)_SEQ2.arw
/06h-58m_(20s)/06h-58m_(20s)_SEQ3.arw
/14h-03m_(58s)/14h-03m_(58s)_SEQ1.arw
/14h-03m_(58s)/14h-03m_(58s)_SEQ2.arw
/14h-03m_(58s)/14h-03m_(58s)_SEQ3.arw
/14h-04m_(01s)/14h-04m_(01s)_SEQ1.arw
/14h-04m_(01s)/14h-04m_(01s)_SEQ2.arw
/14h-04m_(01s)/14h-04m_(01s)_SEQ3.arw
Title: Re: Organizing bracketed photos in folders.
Post by: Phil Harvey on December 26, 2022, 09:13:34 PM
This will require a completely different strategy, and my initial config file will be useless for this purpose.

You want the files to have all the same name even if their individual times are different?  (As may happen if the seconds increment during the sequence.)

This is more complex and will take me a bit of effort.  I'll try to make time for explaining this later if this is what you want to do.

- Phil
Title: Re: Organizing bracketed photos in folders.
Post by: greybeard on December 27, 2022, 06:30:06 AM
A script is probably a better solution (that can still call Exiftool to extract the necessary metadata).

A script would be better at working with multiple files as a single unit.

The script and exiftool calls would be more straightforward to write, test and read.
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on December 28, 2022, 08:32:23 AM
Quote from: Phil Harvey on December 26, 2022, 09:13:34 PMYou want the files to have all the same name even if their individual times are different?  (As may happen if the seconds increment during the sequence.)
Oh, did not think about that.

Guess filename difference in seconds is okay as long stack folder has name of first image in stack and all images from that stack are in same folder.

Take your time by any means. This is just optimization i want to do.

Maybe you or someone can offer more practical naming structure for files because DSC00055.arw is not so useful or informative.
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on February 10, 2023, 04:37:39 AM
Quote from: Phil Harvey on December 26, 2022, 09:13:34 PMThis will require a completely different strategy, and my initial config file will be useless for this purpose.

Hi Phill, converted all my photos using original script you so kindly provided, however found myself in situation when i had to move all images from photosession in one folder once again to preform ananother operation using 3rd party software.

Now i cannot get them back into bracketed folders because file name was changed and original script is indeed not working anymore.


Currently my files look like

\_DSC0001_SEQ1.ARW
\_DSC0002_SEQ2.ARW
\_DSC0003_SEQ3.ARW
\_DSC0004_SEQ1.ARW
\_DSC0005_SEQ2.ARW
\_DSC0006_SEQ3.ARW
\_DSC0007_Single.ARW
\_DSC0008_Single.ARW
\_DSC0009_SEQ1.ARW
\_DSC0010_SEQ2.ARW
\_DSC0011_SEQ3.ARW
\_DSC0012_Single.ARW


Could you please be so kind and suggest a script that would work based on EXIF tags only not relaying on file name at all so files could return back in folders by bracketing like this


\_DSC0001\_DSC0001_SEQ1.ARW
\_DSC0001\_DSC0002_SEQ2.ARW
\_DSC0001\_DSC0003_SEQ3.ARW
\_DSC0004\_DSC0004_SEQ1.ARW
\_DSC0004\_DSC0005_SEQ2.ARW
\_DSC0004\_DSC0006_SEQ3.ARW
\_DSC0007_Single.ARW
\_DSC0008_Single.ARW
\_DSC0009\_DSC0009_SEQ1.ARW
\_DSC0009\_DSC0010_SEQ2.ARW
\_DSC0009\_DSC0011_SEQ3.ARW
\_DSC0012_Single.ARW


Or even better with same timestamp naming suggested in post #11 in this topic. I really appreciate your help.

Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on May 05, 2023, 07:09:43 AM
Quote from: Phil Harvey on December 21, 2022, 09:29:43 AMexiftool -config first_file.config "-directory<firstfile" DIR
Hello Phil i need to run this script trough .bat file where i provide many individual image files and it works great except it creates sub folders in location from which command line is run in my case C:\Users\HP\

Could you advice how can i modify your original command to create sub folder in same location as where the image stored?

Bat file has this
"C:\ExifTool\exiftool.exe" -config "C:\ExifTool\first_file.config" "-directory<firstfile" %*
and it gets input like this
"C:\ExifTool\exiftool.exe" -config "C:\ExifTool\first_file.config" "-directory<firstfile" "c:\images\_DSC0001.ARW" "c:\images\_DSC0002.ARW" "c:\images\_DSC0003.ARW"

Tried using %d, but does not do much.
Title: Re: Organizing bracketed photos in folders.
Post by: StarGeek on May 06, 2023, 12:40:28 PM
Quote from: JobWellDone on May 05, 2023, 07:09:43 AMTried using %d, but does not do much.

%d would be the answer, but you have to put it in the correct location and read FAQ #27 (https://exiftool.org/faq.html#Q27).

What you want is probably
"-directory<%%dfirstfile"
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on May 07, 2023, 11:05:14 PM
Quote from: StarGeek on May 06, 2023, 12:40:28 PMWhat you want is probably
"-directory<%%dfirstfile"
getting error Warning: Invalid tag name '%dfirstfile'. Use '=' not '<' to assign a tag value - C:/one/_DSC0003.ARW

even if i use = to assogn value custom tag firstfile is not resolved when using %%firstfile
Title: Re: Organizing bracketed photos in folders.
Post by: StarGeek on May 08, 2023, 11:46:01 AM
Ah, ok, I forgot the dollar sign as it's now a more complex tag copy.

"-directory<%%d$firstfile"
Title: Re: Organizing bracketed photos in folders.
Post by: JobWellDone on May 09, 2023, 01:07:27 AM
Quote from: StarGeek on May 08, 2023, 11:46:01 AM"-directory<%%d$firstfile"
That works, thank you.