Copying EXIF from One image to another using EXIF Tool Taking too long

Started by vyshak, April 24, 2018, 12:06:12 PM

Previous topic - Next topic

vyshak

Hi,

I'm coding in C#.I'm trying to copy EXIF Data from one image to another using the following code
I have a list of files and im trying to copy by iterating through the list

foreach(string cpath in filelist)
{
    string path = "-overwrite_original -TagsFromFile " + "\"" + file + "\"" +" "+ "\"" + outdir + "\\" + Path.GetFileNameWithoutExtension(file) + ext + "\"";
                        runCmd(path);
}

  public void runCmd(string command)
    {

        ProcessStartInfo cmdsi = new ProcessStartInfo("exiftool.exe");
        cmdsi.WindowStyle = ProcessWindowStyle.Hidden;
        cmdsi.Arguments = command;
        Process cmd = Process.Start(cmdsi);
        cmd.WaitForExit();   
    }


When directly run from command line,the tool is quick.But when the command is executed from a winform app,it takes much greater time.
The issue occurs because exif tool is started newly during each iteration.The startup of the tool takes a lot of time.How can i solve this issue?
Please advice.

StarGeek

As I commented on your StackOverflow post, running exiftool on each file is much slower due to the startup time of exiftool.  See Common Mistake #3edit: (I didn't notice you had replied to my comment there, but this well help anyone else get up to speed.)

Looking closer at your code, you'll want to write a temp file along these lines

-TagsFromFile
[i]InputFile[/i]
[i]OutputFile[/i]
-overwrite_original
-execute
-TagsFromFile
[i]InputFile[/i]
[i]OutputFile[/i]
-overwrite_original
-execute
-TagsFromFile
[i]LastInputFile[/i]
[i]LastOutputFile[/i]
-overwrite_original

(Take note, there is not an -execute command after the final file.  Also, no quotes are needed around filenames in the temp file.)

You would then run the command
exiftool -@ /path/to/tempfile.txt

Another option if your program is running constantly, would be to look into the -stay_open option.  There are examples on the forum here but I can't really advise on that as I've never used it.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

vyshak


vyshak

I have written the following code,it works.Hope its correct

-TagsFromFile
a.jpg
b.jpg
-overwrite_original
-execute
-TagsFromFile
a2.jpg
b2.jpg
-overwrite_original


StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

vyshak

Thanks,but i need to report progress in the c# application.Is there a way to do that while using @ option?

StarGeek

Just realized that the progress option wouldn't work well with the multiple executes.

But you're going to have to parse the output from exiftool in some way, as I don't believe it has any other way to communicate.

What you could do is use the -echo option.  Add it in before the -TagsFromFile and have it print your progress, something like -echo "File 1 of ##, -echo "File 2 of ##, etc.  You would then have to parse the output of exiftool and you could use that to show the progress of your program.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype


StarGeek

I don't know C#, so I don't know how to make it read the output from exiftool (though I did find this Stackoverflow question that might cover it).  But on the exiftool side, your temp file with the -echo option would be something like:

-echo
File 1 of 10
-TagsFromFile
a.jpg
b.jpg
-overwrite_original
-execute
-echo
File 2 of 10
-TagsFromFile
a2.jpg
b2.jpg
-overwrite_original


You would then just parse exiftool's output for the "File # of #" (or whatever format you want to use) and use that to monitor your progress.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype


vyshak

I ended up using the stayopen Flag and the arguments file.It works nicely :)
Just once last question

I remember using this option earlier
runCmd("-overwrite_original -thumbnailimage= " + "\"" + outdir + "\\" + Path.GetFileNameWithoutExtension(file) + ext + "\"");

I think it was used to correct some issue with the preview image.But i dont remember exactly what was the issue that lead to using this command.
Could you please advice.

Phil Harvey

That command deletes the thumbnail image.  This would make sense if it was a different image.  But it would be better to prevent copying the thumbnail in the first place:

-TagsFromFile
a.jpg
--thumbnailimage
b.jpg
-overwrite_original
-execute
[...]


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

vyshak

Yes,i was resizing the image and copying the exif,So i had to delete the thumbnail.Ignoring the thumbnail is the best solution.

Thanks for your reply and the great tool :)