How can i do these CLI commands in C++ Interface for Exiftool?

Started by refrain, March 05, 2015, 01:09:40 AM

Previous topic - Next topic

refrain

Hello,

How can i do these  CLI command below in C++ Interface for Exiftool?

First, i want to add new tags to all my images using Exiftool_config.
exiftool -config ExifTool_config /home/intannf/try


These are EXiftool_config that i wrote:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::GPS::Main' => {
0xd000 => {
Name => 'GPSLatitude',
Writable => 'rational64s',
},
0xd001 => {
Name => 'GPSLongitude',
Writable => 'rational64s',
},
},
'Image::ExifTool::MIE::Meta' => {
AirSpeedSensor => {
Writable => 'rational64u',
Unit => [ 'm/s' ],
},
HeightSensor => {
Writable => 'rational64u',
Unit => [ 'm' ],
},
},
);
1;


and this is another CLI command that i used to import csv file to an image.
exiftool -csv=test.csv /home/intannf/IMG_3511.JPG.
actually i want to import those file into all images in a directory, but i have a problem how to import csv file to those images while it needs source file in csv file.

I hope somebody will help me.

Thank you,
Intan

Phil Harvey

Hi Intan,

First I suggest you get this working from the command line, and there are a number of problems here.  Once you get it working from the command line, it will be easy to port this to to the C++ interface.

It seems you want to read GPSLatitude, GPSLongitude, AirSpeedSensor and HeightSensor information from a CSV file and write it to images?  (JPG?)  Correct?

1) You shouldn't re-define the standard GPS GPSLatitude/GPSLongitude tags.  These tags are already defined according to the EXIF standard.

2) You can't create MIE metadata in a JPG image, so your custom AirSpeedSensor and HeightSensor tags should use a different metadata type.  I suggest XMP.  Look at the XMP-xxx example in the sample config file.

3) Your CSV file must look like this to use the command you gave:

SourceFile,GPSLatitude,GPSLongitude, AirSpeedSensor, HeightSensor
/home/intannf/IMG_3511.JPG,45.4345,72.2122,234,7832
...


4) You must also write GPSLatitudeRef and GPSLongitudeRef when writing EXIF GPS.  So your command should look like this to process all files in the directory:

exiftool -csv=test.csv -gpslatituderef=N -gpslongituderef=W /home/intannf/

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

refrain

Hi, Phil.

Thanks for your suggestion. I have tried it, but still have some problem that make me confused.

First, these are my new 'ExifTool_Config' file. Is it true?
%Image::ExifTool::UserDefined = (
'Image::ExifTool::XMP::Main' => {
xxx => {
SubDirectory => {
TagTable => 'Image::ExifTool::UserDefined::xxx',
},
},
},
);

%Image::ExifTool::UserDefined::xxx = (
GROUPS => { 0 => 'XMP', 1 => 'XMP-xxx', 2 => 'Image' },
NAMESPACE => { 'xxx' => 'http://ns.myname.com/xxx/1.0/' },
    WRITABLE => 'string',
AirSpeedSensor => { Writable => 'rational' },
HeightSensor => { Writable => 'rational' },
);
1;


and this is the CSV file that i have.
SourceFile,GPSlatitude,GPSlongitude,GPSlatituderef,GPSlongituderef,AirSpeedSensor,HeightSensor
/home/intannf/try/IMG_5731.JPG,-8.639298°,116.311607°,N,W,155,7327


below is the command line that i used to add new tags to all images in the directory. there are 2 images in those directory and fortunately, it has been updated successfully.
exiftool -config ExifTool_config /home/intannf/try/

But, when i tried to import those CSV file in the directory there's some error like this below. I think it means i have to write all source file in the CSV file same as filename of images in the directory, right?
exiftool -csv=test4.csv /home/intannf/try/
No SourceFile '/home/intannf/try/IMG_5732.JPG' in imported CSV database
(full path: '/home/intannf/try/IMG_5732.JPG')
    1 directories scanned
    1 image files updated


But, i am still confused how to write those command line in c++ interface's script. Would you give me the examples of it?

Then, why do i have to write GPSLongitudeRef and GPSLatitudeRef when writing EXIF GPS? Because actually i just need GPSlatitude and GPSlongitude.

Thank you,
Intan

Phil Harvey

Hi Intan,

You are very close.  Change your CSV file to this:

SourceFile,GPSlatitude,GPSlongitude,GPSlatituderef,GPSlongituderef,AirSpeedSensor,HeightSensor
/home/intannf/try/IMG_5731.JPG,8.639298,116.311607,N,W,155,7327


And use this command:

exiftool -config ExifTool_config -csv=test4.csv /home/intannf/try

You will still get warnings for files in /home/intannf/try that don't have entries in the CSV file, but it will update the files that do have entries.  In your case, it updated 1 file, but it wouldn't have written your custom tags because you didn't use your config file.

- Phil

Edit:  You should change "N,W," in the CSV file to your specific geographic quadrant.
...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 ($).

refrain

Ah, i think i get it. So, if i run the command line below, the custom tags will be written to all of images in the directory. Is it true?
exiftool -config ExifTool_config -csv=test4.csv /home/intannf/try

What if i dont write the GPSlongituderef and GPSlatituderef? Will it cause some trouble?

Intan

Phil Harvey

Hi Intan,

Quote from: refrain on March 05, 2015, 11:27:03 AM
So, if i run the command line below, the custom tags will be written to all of images in the directory. Is it true?

Correct.

You don't have to write the reference directions if you want.  But without them, an EXIF-compliant reader won't know what to do with these coordinates.  However, if they are the same for all your images, you don't need to read them from the CSV file.  Instead, you could do this:

exiftool -config ExifTool_config -csv=test4.csv -gpslatituderef=N -gpslongituderef=W /home/intannf/try

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

refrain

Okay, i get it now. Thanks, Phil.
But i am still blind to write those command line in c++ interface' script. Would you give me an example of it?
I have read the examples' script of cpp exiftool, but it looks different with command line. That is worrying me, something that I can't stop thinking about.  :'(

Intan

Phil Harvey

Via the C++ interface, the code would look like this:

#include "ExifTool.h"
ExifTool *et = new ExifTool();
et->Command("-config\nExifTool_config\n-csv=test4.csv\n-gpslatituderef=N\n-gpslongituderef=W\n/home/intannf/try");
et->Complete();


The Complete() call waits for the command to complete.  After this, you should probably GetError() to check for ExifTool errors, provided that Complete() returned a positive number.

- Phil

Edit: I didn't remember any of this myself, but I found the C++ Interface for ExifTool documentation very helpful. :)
...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 ($).

refrain

Thanks, Phil. You're so helpful!  ;D
Yeah, i am still learning the documentaion and now I will try to continue programming. Hope you will help me again if i get problems someday. Because I have to finish this project within two weeks. Hope it will be finished as soon as possible.  :)

Intan

refrain

Quote from: Phil Harvey link=topic=6355.msg31511#msg31511 date=1425578275
code]#include "ExifTool.h"
ExifTool *et = new ExifTool();
et->Command("-config\nExifTool_config\n-csv=test4.csv\n-gpslatituderef=N\n-gpslongituderef=W\n/home/intannf/try");
et->Complete();[/code]

Hi, Phil.
When i compile those script, i got this error.
test.cpp:2:29: error: the default argument for parameter 0 of 'ExifTool::ExifTool(const char*, const char*)' has not yet been parsed
test.cpp:2:29: error: the default argument for parameter 1 of 'ExifTool::ExifTool(const char*, const char*)' has not yet been parsed
test.cpp:3:1: error: 'et' does not name a type
test.cpp:4:1: error: 'et' does not name a type


What does it mean? I dont know what to do. I am still learning.

Intan

Phil Harvey

Hi Intan,

Yes, I left out some things that you would need to be able to compile this as an application.  Here is the complete source code:

#include <iostream>
#include "ExifTool.h"

using namespace std;

int main(int argc, char **argv)
{
ExifTool *et = new ExifTool();
et->Command("-config\nExifTool_config\n-csv=test4.csv\n-gpslatituderef=N\n-gpslongituderef=W\n/home/intannf/try");
et->Complete();
delete et;
return 0;
}


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

refrain

Quote from: Phil Harvey on March 08, 2015, 09:14:36 AM
Hi Intan,

Yes, I left out some things that you would need to be able to compile this as an application.  Here is the complete source code:

#include <iostream>
#include "ExifTool.h"

using namespace std;

int main(int argc, char **argv)
{
ExifTool *et = new ExifTool();
et->Command("-config\nExifTool_config\n-csv=test4.csv\n-gpslatituderef=N\n-gpslongituderef=W\n/home/intannf/try");
et->Complete();
delete et;
return 0;
}


- Phil

Hi, Phil.
I have tried to run those script using geany. But when i tried to build and compile, it always give me error. I have tried to build it using make file. But the result is the same.
Do you have any idea?

Regards,
Intan

Phil Harvey

It would be helpful if you told me what the error was.
...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 ($).

refrain

I tried command and build it using Geany on Ubuntu. First i have to set build command and i set them like this below.
on compile:
g++ main.cpp -lserial -libimage-exiftool-perl
on build:
g++ -I/usr/share/libimage-exiftool-perl

but when i tried to compile and build them, i have error like this.
when compile it:
g++ main.cpp -lserial -libimage-exiftool-perl (in directory: /home/intannf/cpp_exiftool/bismillah)
g++: error: main.cpp: No such file or directory
Compilation failed.

when build it:
g++ -I/usr/share/libimage-exiftool-perl (in directory: /home/intannf/cpp_exiftool/bismillah)
Compilation failed.
g++: fatal error: no input files
compilation terminated.


I just dont know why it can be like that. I never used Geany before. Do you have any idea?

Phil Harvey

Hi Intan,

There are a number of things wrong with what you are trying to do.

I recommend downloading cpp_exiftool and typing "make" in that directory to see how the example programs are compiled.  Then it may be easier to edit one of the examples instead of trying to build it yourself.

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