Organizing bracketed photos in folders.

Started by JobWellDone, December 21, 2022, 06:59:36 AM

Previous topic - Next topic

JobWellDone

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.

Phil Harvey

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

JobWellDone

#2
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

Phil Harvey

You can add -q -q to the command to suppress warnings, but that will also drop the summary messages.

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

JobWellDone

#4
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



Phil Harvey

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

JobWellDone

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.

JobWellDone

#7
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?

Phil Harvey

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

JobWellDone

#9
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?


Phil Harvey

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

JobWellDone

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

Phil Harvey

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

greybeard

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.

JobWellDone

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.