ExifTool "Variable" That Stores File Counter (As with -progress)?

Started by lyndess, August 11, 2019, 08:59:29 PM

Previous topic - Next topic

lyndess

I am trying to use a single ExifTool command to parse a folder of image files and then write the values of certain tags into a single text file.  The text file is structured based on a "format file" that is specified as a parameter to -p FMTFILE.

The ExifTool command looks something like this:
exiftool.exe -p "PrintFormat file.fmt" -progress "C:\MyImageFolder\" -ext .DNG > "MyOutputFile.txt"

(I tried to simplify the command here so you don't have to read long path names, etc.)

The format file has [HEAD] and [BODY] sections; I am able to extract tag values, and everything works great.  Within the [BODY] section, for example, I can get the image file name with $FileName, the creation date formatted with ${createdate#;DateFmt("%Y-%m-%d_%H:%M:%S")}, etc. 

What I would like to do is also include the count of the file being processed -- with the first file being "1", the second file being "2", etc.

Somehow, ExifTool keeps track of this count, because you can view it in the command/console window if you add the -progress option.  Are there any "variables" I can reference in my format file to extract this "count" number?

Thank you!

- Scott




StarGeek

See FileSequence on the Extra tags page

   sequence number for each source file when extracting or copying information, including files that fail the -if condition of the command-line application, beginning at 0 for the first file. Not generated unless specifically requested or the RequestAll API option is set

To get it to start at 1, you would use ${FileSequence;$_+=1}
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lyndess

Well, after hours of researching this issue and coming up with nothing, I'm glad I asked the question on this forum.  The solution works perfectly!  Thank you!

lyndess

One more question ...

Now that I have the file sequence number, I want to run use it with the modulo operator against a userParam that is defined on the ExifTool command line and "passed into" the format file.

So, I want:
bracket="${FileSequence#;$_+=1} % ${bracketnumber#}"

... to produce the following in the output file:
bracket="2"

... when FileSequence = 8 and bracketnumber=3, for example.  (bracketnum is the userParam.)

Any suggestions?

Right now, this code produces (uncalculated) text output, such as:
bracket="8 % 3"

StarGeek

I'm not sure how to access the userparam from within the variable.  There is the ability to use $self->GetValue('TAG'), but I wasn't able to access the userparam with that in my quick test.  So, I tried to do it the other way.  But then there's the problem that FileSequence isn't normally created. 

Here's my final result:
exiftool -p "${bracketnumber;$_=($self->GetValue('FileSequence')+1) % $_ }" -api RequestAll -userparam bracketnumber=2 <FileOrDir>

It takes BracketNumber "tag", uses $self->GetValue to get the FileSequence value, adds 1, and then modulo that against the original value of BracketNumber.  -api RequestAll is needed to make sure FileSequence is created (you'll get a Advanced formatting expression returned undef error without it), but if somewhere else you access FileSequence directly, it can be removed.

If BracketNumber isn't used anywhere else, it might be better to just use ${FileSequence#;$_=($_+1) % 2}, filling in the BracketNumber directly.

Maybe Phil can come up with something better in the morning.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

To access a UserParam from within an advanced formatting expression, do this:

$self->Options('UserParam','MYPARAM')

But it seems you are using an existing tag (BracketNumber) and not a user parameter.

I can't think of a better way to do this than what StarGeek has already suggested.

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

StarGeek

I assumed BracketNumber was a userparam based upon this line
Quote from: lyndess on August 12, 2019, 12:26:14 AMI want to run use it with the modulo operator against a userParam that is defined on the ExifTool command line and "passed into" the format file.
but I can't seem to find it in a google search of the Tag Names pages.

But now given the option to grab userparams (upon seeing the command, I now remember having seen it before, adding to my notes) from the advanced formatting, I would think that this command would be better, as it doesn't need the -api RequestAll option, meaning exiftool wouldn't have to calculate a bunch of tags it doesn't ordinarily create.

exiftool -p "${FileSequence;$_=($_+1) % $self->Options('UserParam','BracketNumber')}" -userparam bracketnumber=2 <FileOrDir>
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lyndess

Thank you, guys!  I will try this.  (Sorry for the delay in responding; I was on business travel this past week ... )

lyndess

It worked! 

Because the format file outputs multiple lines, I moved "${FileSequence;$_=($_+1) % $self->Options('UserParam','BracketNumber')}" from the command line into the format file.  Then the issue I had was that -- if the BracketNumber was 3 -- the result would be 1, 2, 0, 1, 2, 0 ... when I wanted 1, 2, 3, 1, 2, 3 ...  So that I just had to subtract 1 from the dividend and then add it back after the modulo operation.

If you're wondering why I'm doing this ... I sometimes create 360 panoramic images from drone photographs, and sometimes I bracket each "frame."  I use Autopano Giga to stitch the images together, but it often doesn't detect the correct placement of all the images.  You can improve the result by feeding Autopano with a Papywizard template file that specifies the pitch, yaw, and rotation of each image.  It turns out that DJI drones embed this data into the image EXIF, so I created a (Windows) batch file that I can drag-and-drop a single image onto, and the batch file will call ExifTool to process all similar images in that folder.  ExifTool uses a "multi-line" format file to generate the Papywizard XML file.  When you use this XML file in Autpano, the stitching is consistently accurate.