ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: fxstein on November 01, 2022, 04:21:21 PM

Title: if Condition issue when combined with if4
Post by: fxstein on November 01, 2022, 04:21:21 PM
Hi,

Chasing a strange phenomenon with tag names in -if when combined with -if4 in the same execution.

Here is an example that works:

exiftool -a -G1 -s -CameraSerialNumber /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 -if '$GoPro:CameraSerialNumber eq "C3464224512442"'

Output:
[GoPro]         CameraSerialNumber              : C3464224512442

Now when I add an -if4 parameter it stops working:

exiftool -a -G1 -s -CameraSerialNumber /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 -if '$GoPro:CameraSerialNumber eq "C3464224512442"' -if4 '${FileCreateDate#;DateFmt("%Y%m%d%H%M%S")} ge "20221004" and ${FileCreateDate#;DateFmt("%Y%m%d%H%M%S")} lt "20221030"' -v

Output:
Condition: Use of uninitialized value $info{"GoPro:CameraSerialNumber"} in string eq - /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4
-------- /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 (failed condition)
    1 files failed condition


I have also tried a simplified version:
exiftool -a -G1 -s -CameraSerialNumber /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 -if '$GoPro:CameraSerialNumber eq "C3464224512442"' -if4 '1 eq 1' -v

Output:
Condition: Use of uninitialized value $info{"GoPro:CameraSerialNumber"} in string eq - /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4
-------- /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 (failed condition)
    1 files failed condition


Same issue. The moment any -if4 condition gets added, the -if condition stops working. Same if I switch the order of them.
Title: Re: if Condition issue when combined with if4
Post by: StarGeek on November 01, 2022, 05:02:23 PM
The docs on the -if option (https://exiftool.org/exiftool_pod.html#if-NUM-EXPR) in regards to the number suffix say
    see the -fast option documentation for details

The appropriate docs on the -fast option (https://exiftool.org/exiftool_pod.html#fast-NUM) (emphasis mine)
     -fast4 doesn't even read the file header, and returns only System tags and a FileType based on the file extension

If you use -if4, you cannot check the condition of an embedded tag as no embedded tags are read.
Title: Re: if Condition issue when combined with if4
Post by: fxstein on November 01, 2022, 06:00:06 PM
Thank you! That is all very clear.

If you take another look at the example I provided you will find that the tag check is in a -if check without a NUM.

What the documentation does not seem to spell out is that if you add multiple -if checks they get upgraded (downgrade to the lowest common capability) to the highest NUM

it seems that if you combine -if condition -if4 another-condition both seem to become -if4
Title: Re: if Condition issue when combined with if4
Post by: fxstein on November 01, 2022, 06:03:01 PM
But that let me to try another variant with turning -if into -if0 and that works.

exiftool -a -G1 -s -CameraSerialNumber /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 -if4 '1 eq 1' -if0 '$GoPro:CameraSerialNumber eq "C3464224512442"'

now does what is expected:
[GoPro]         CameraSerialNumber              : C3464224512442

But it only works when the -if4 comes before (to the left) of -if0

Therfore:
exiftool -a -G1 -s -CameraSerialNumber /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 -if0 '$GoPro:CameraSerialNumber eq "C3464224512442"' -if4 '1 eq 1'

will fail again as before:
Condition: Use of uninitialized value $info{"GoPro:CameraSerialNumber"} in string eq - /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4
-------- /Users/oratzes/goprox-test/processed/MP4/2022/20221011/P_20221011151430_GoPro_Hero10_2442_GX011643.mp4 (failed condition)
    1 files failed condition

Title: Re: if Condition issue when combined with if4
Post by: Phil Harvey on November 01, 2022, 07:19:55 PM
You're right, this isn't documented.  I'll fix this.

Currently, multiple -if conditions are all evaluated at once at the level (ie. NUM) of the last -if option which includes a NUM.

I should change this so they use the lowest NUM.

- Phil
Title: Re: if Condition issue when combined with if4
Post by: fxstein on November 02, 2022, 02:29:49 AM
Is there any way to keep both?

Run the -if4 first and only load extra data for matches. That way you get the speed benefit from -if4 and only incur the cost of -if0 when needed.Since they are AND together, that would be a viable choice.
Title: Re: if Condition issue when combined with if4
Post by: Phil Harvey on November 02, 2022, 07:38:45 AM
Adding a potential separate pass for each -if option would complicate the code a lot, and I don't think it would be worth the cost since I doubt anyone else would ever take advantage of this feature.

- Phil