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.
As I commented on your StackOverflow (https://stackoverflow.com/questions/49997366/copying-exif-from-one-image-to-another-using-exif-tool-taking-too-long) post, running exiftool on each file is much slower due to the startup time of exiftool. See Common Mistake #3 (https://stackoverflow.com/questions/49997366/copying-exif-from-one-image-to-another-using-exif-tool-taking-too-long). edit: (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 (https://exiftool.org/exiftool_pod.html#stay_open-FLAG). There are examples on the forum here but I can't really advise on that as I've never used it.
Thanks a lot :),i will check and get back.
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
Is there a way to report progress?
Check out the -progress option (https://exiftool.org/exiftool_pod.html#progress-:-TITLE).
Thanks,but i need to report progress in the c# application.Is there a way to do that while using @ option?
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 (https://exiftool.org/exiftool_pod.html#echo-NUM-TEXT). 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.
Can you please post an example.
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 (https://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results) 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.
Thanks :),will check and get back.
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.
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
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 :)