I can't get tag values when ExifTool invoked with Comspec in AutoIt

Started by GordO, June 18, 2018, 11:17:42 PM

Previous topic - Next topic

GordO

To obtain video file frame width and height, ExifTool works splendidly when I invoke it from a standard Windows CMD window :). But when I use the exact same command line (or any of about 40 alternative command lines) in an AutoIt Comspec "Run()" function call, the values never come through!

I do see the Tag names, "SourceImageWidth" and "SourceImageHeight" just fine, but their values always come out as dashes (which would indicate that the tag values are not present).  I've been struggling to get this working for days, but no matter what I try, it NEVER works!

Here are several Windows CMD command lines that all work perfectly (note that I've added the ExifTool program directory to the PATH environment variable, so I don't need to specify a path or the .exe file extension): ExifTool -f -ignoreMinorErrors -SourceImageWidth -SourceImageHeight "C:\A Video File.mp4" Results:
SourceImageWidth: 1280
SourceImageHeight: 720


ExifTool -fast2 -f -veryShort -ignoreMinorErrors -SourceImageWidth -SourceImageHeight "C:\A Video File.mp4" Results are as above.

CMD.exe /C ExifTool.exe -latin -fast2 -f -veryShort -ignoreMinorErrors -SourceImageWidth -SourceImageHeight  "C:\A Video File.mp4" Results are as above.

But when I try the following AutoIt code snippet...

Local $s_Cmd, $s_CmdRes, $i_PID, $i_Stat, $i_RetCode, $i_CmdResLen
Local $s_Cmd = @ComSpec & " /C ExifTool.exe -latin -fast2 -f -veryShort -ignoreMinorErrors -SourceImageWidth -SourceImageHeight "
$s_Cmd &= '"C:\A Video File.mp4"'

$i_PID = Run( $i_Cmd, "", @SW_HIDE, $STDOUT_CHILD )
If ($i_PID = 0) Or (@error <> 0) Then
$i_RetCode = @error
Return SetError( $i_RetCode, ,0, -1 )
EndIf

$i_Stat = ProcessWaitClose( $i_PID, 20 )
If $i_Stat = 0 Then Return SetError( -2, 0, -2 )

$s_CmdRes = StdoutRead( $i_PID, True )
$i_RetCode = @error
If $i_RetCode <> 0 Then Return SetError( $i_RetCode, 0, -3 )
$i_CmdResLen = @extended
If ($s_CmdRes = "") Or ($i_CmdResLen < 20) Then Return SetError( -4, 0, -4 )

MsgBox($MB_OK, "ExifTool Test", $s_CmdRes)
Exit
...
The results are always as follows:
SourceImageWidth: -
SourceImageHeight: -


What's going on? You'll notice that I tried adding the "-latin" and other options in case I was experiencing a Unicode issue or whatever, but with or without them, it always works when I type the command into a CMD window, and it NEVER works when I try it in an AutoIt script or executable!

BTW: I'm running 64-bit Windows 7 Pro on a high-end desktop, and I've got the latest version of AutoIt installed.

Please help this newbie out?  Thanks![/code]

StarGeek

Try putting in the full path to exiftool.  It's been a while since I tried running exiftool from autoit and I can't find any of my old scripts, but I seem to recall that was something I had to do.
* 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).

GordO

Quote from: StarGeek on June 19, 2018, 12:03:48 AM
Try putting in the full path to exiftool.  It's been a while since I tried running exiftool from autoit and I can't find any of my old scripts, but I seem to recall that was something I had to do.

Hey, thanks for your reply, kindly StarGeek!

I was in the process of posting that I had figured out what I was doing wrong, but before I could type anything, I saw a notice saying that a new reply (yours, obviously) had just been posted and said I should probably check it out, which is what I'm doing now.

The problem was obviously not caused by ExifTool, since it worked perfectly from the command line.  And a few minutes ago I learned that wasn't anything wrong with my AutoIt code either. So, what's left?  It turned out that the metadata for the file I had been using as a test did not actually contain those two tags!

I was slow on the uptake, but I should have tried harder before posting this OP. But because I used the "-f" flag to force a response, since those two tags are not present in that test file, of course it was going to return a dash as an output string!  Silly me.

In the test file I used, the tag names for the width and height are "ImageWidth" and "ImageHeight", respectively.  And there's another tag named "ImageSize" that combines both values in a single string. But I'm not sure how to adapt my code to handle files with different tag names for those values though.  I can only think of one basic approach, which is to run ExifTool with only the "-s" option first, then search the results for tags containing the substrings "width" and "height" and thus get the correct tag names from there.

But I'm a ExifTool newb, so there's probably one or more easier alternatives that I'm ignorant of.  Any suggestions?

Thanks again!

StarGeek

Use ImageWidth and ImageHeightSourceImageWidth and SourceImageHeight appear to be MP4 video specific and won't appear in an image file or other types of video files I checked (MKV, WMV).  The first two should be based upon the actual file data.

If you feel like searching through the output, then use wildcards to limit the output to just width and height:
exiftool -*width* -*height* FILE
* 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).