José Ignacio Fernánd February 2016

Extract dates exif of images at c++ in variables

I need optimize this code. Currently, this code works. I can extract the datetimeoriginal tag in a file using the extern tool "exiftool". But this is too slow when this process is repeated. is there a way the extract this information in variables directly?

void image::add_info_creation_date(char *name_jpg){  
//Execute exiftool in bash
stringstream ss;
ss << "exiftool.exe -datetimeoriginal -timezone images\\" << name_jpg << " >> temporal.txt";
error = system(ss.str().c_str());
if (error != 0){
    printf("The value returned was: %d.\n", error);
    ss.clear();
    exit(1);
}
ss.clear();
...
}

Sorry for my grammar, i am not native english speaker.

Answers


Useless February 2016

is there a way the extract this information in variables directly?

Yes, it is possible.

Your options are to either find and use a library which can read the EXIF information for you, or to read & understand the JPEG & EXIF formats, and read the file yourself.

Since a quick search turns up several libraries that do these things, and since at least some documentation is available for both standards, it doesn't seem too hard.

If you read the file yourself, note that the JPEG file format contains multiple tagged sections, including both the image and its metadata - you just need to walk the sections until you find the EXIF data and then parse that.


gmcgath February 2016

Executing ExifTool once for each file can be slow, but there's a way to run it so you can feed it a stream of commands. First, create an argument file and keep it open for output; let's call it args.txt. Then launch

exiftool -stay_open True -@ args.txt

For each file, write the arguments, one argument per line, something like this, to args.txt:

-datetimeoriginal
-timezone
{filename}
-execute

When finished, write the following to args.txt:

-stay_open
False

This may get you sufficient performance. Don't close args.txt till you're finished, but it will help if you flush any buffers after each -execute.

Post Status

Asked in February 2016
Viewed 2,277 times
Voted 10
Answered 2 times

Search




Leave an answer