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 Tag | Shot 1 | Shot 2 | Shot 3 | Single Shot |
Exposure Compensation | 0 | -2 | +2 | 0 |
Sequence Number | 1 | 2 | 3 | Single |
Sequence Image Number | 1 | 2 | 3 | 1 |
Sequence File Number | 1 | 2 | 3 | 1 |
Release Mode | Exposure Bracketing | Exposure Bracketing | Exposure Bracketing | Normal |
Release Mode 2 | Continuous - Exposure Bracketing | Continuous - Exposure Bracketing | Continuous - Exposure Bracketing | Normal |
Release Mode 3 | Bracketing | Bracketing | Bracketing | Normal |
Exposure Mode | Auto bracket | Auto bracket | Auto bracket | Manual |
Sequence Length | 3 shots | 3 shots | 3 shots | 1 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.
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
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
You can add -q -q to the command to suppress warnings, but that will also drop the summary messages.
- Phil
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
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
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.
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?
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
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 DIRIf 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 DIRthen 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?
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
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
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
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.
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.
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.
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.
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"
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.ARWeven if i use
= to assogn value custom tag
firstfile is not resolved when using
%%firstfile
Ah, ok, I forgot the dollar sign as it's now a more complex tag copy.
"-directory<%%d$firstfile"