Launching Exiftool Once for Multiple Commands

Started by QPRJohn, July 03, 2014, 02:16:18 PM

Previous topic - Next topic

QPRJohn

Firstly can I start this thread by thanking Curtis who's demo of exiftool .Net wrapper (written in vb.net) has helped me overcome the problem below using his ExifToolIO project.

I wanted to find out where I have gone wrong with my own code, or if I cannot achieve the following:-

I have code using Exiftool in VB.Net to write tags to images using -tagsfromfile.

        Dim ExifTool As New Process
        ExifTool.StartInfo.FileName = Application.StartupPath & "\Documents\exiftool.exe"


        ExifTool.StartInfo.Arguments = "-overwrite_original -tagsFromFile" + " " + Chr(34) + EditedXMPSaveDirectory + Chr(34) + " " + Chr(34) + Filename + Chr(34)
        ExifTool.StartInfo.UseShellExecute = False
        ExifTool.StartInfo.RedirectStandardOutput = True
        ExifTool.StartInfo.CreateNoWindow = True
        ExifTool.Start()



I have put the code in a loop that updates tags in multiple files selected from a file dialogbox.

I have found that this process puts great demand on the CPU (100%) from start to finish.

I am aware of the -stayopen argument, I'm not sure how to use it, or if it's the right method to use.

I've tried putting the following code before the files are selected with the open file dialog box.

        Dim ExifTool As New Process
        ExifTool.StartInfo.FileName = Application.StartupPath & "\Documents\exiftool.exe"

        Dim BaseArgs As String = "-stay_open True -fast2 -m -overwrite_original"

        ExifTool.StartInfo.Arguments = BaseArgs
        ExifTool.StartInfo.UseShellExecute = False
        ExifTool.StartInfo.RedirectStandardOutput = True
        ExifTool.StartInfo.CreateNoWindow = True
        ExifTool.Start()


The following code is in the "loop" for each file selected:-

                Dim strNewXMPArg As String = strNewXMPArgs()

                'copy all tags from IngestXMP write tags for copy protected files and selected Adobe labels and PM Ratings
                ExifTool.StartInfo.Arguments = " -execute " + BaseArgs + " " + Chr(34) + XMPSaveDirectory + Chr(34) + " " _
                   + strNewXMPArg + " " + Chr(34) + NewImagePath + Chr(34)


I've added the -execute argument assuming that it will execute the "Arguments" for each selected file.

When the "loop" has finished I use the code: -

ExifTool.Close()

To end the process. (I have included the argument -stayopen false but it remains open)

It will not copy any of the "tags" to the images, similarly it leaves Exiftool open after it completes.

I've tried various combinations of this but cannot get it to work.

What am I doing wrong?

In a previous post I've read Phil states in the post "For best performance, you should only launch exiftool once.

In your case it may be as simple as calling ExifTool with the names of all the files you want to process on the same command line."


How can I achieve this?

John


Phil Harvey

Hi John,

The wrapper should handle the -stay_open and -execute internally if it uses these features, and looking at Curtis' ExifToolIO.vb this seems to be the case.

The process should be to start exiftool, send commands, then stop exiftool.  I don't know anything about Curtis' interface, but I'm pretty sure you don't want to be setting up StartInfo.Arguments inside a loop.  Instead, it looks to me like you should be calling Cmd() then Excecute() in the loop.

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

Curtis

Hi John,

Yes, Phil is correct.  I think where your misunderstanding is coming from is that once you have the exiftool process started and you use -stay_open, then to send commands to exiftool you need to write to stdinp (or whatever file you have setup for the command input file).  That is where exiftool is looking for its commands to come from (or from a file name that you provide, but this slows things a little because it will involve disk I/O).  The ExifTool.StartInfo.Arguments is just used when exiftool process initially starts up so you can not use it in a loop.  Once you do the ExifTool.Start,  changing any of the Exiftool.StartInfo members will have no effect on the running exiftool process.

If you look in my ExifToolIO.vb code you will see I set up the variable CmdStream as standardinput (if no file name is given) in the StartExifToolProcess sub and then in the Execute sub I write to CmdStream which is the way commands are sent to exiftool.  Then the other tricky part is waiting for the output from exiftool to be complete (ie get '{ready}') which is done in my OutputDataHandler event handler and in the stdout function.

My ExifToolIO code is really very basic and does just the minimum to communicate with exiftool.  May be best to just study ExifToolIO.vb and try to understand it.  If you get stuck email me or post here.

Good Luck!
Curtis

QPRJohn