Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read/Write file metadata using C/C++

Tags:

c++

c

xml

metadata

Searched through net, could't find a way to read/write file metadata using C or C++, however, there are tools available for this, and also there are API's in C# and Java to do this. But I want to do it from scratch in C or C++.

For example, read/write image metadata.

Have found out that there are three formats in which metadata is written to files. EXIF, IPTC and XMP.

Thanks.

like image 204
Rajendra Uppal Avatar asked May 13 '10 07:05

Rajendra Uppal


2 Answers

Why would you want to do it from scratch?

Anyway, you need documentation and you may also want to look at an existing library for helps, expecially if you have no experience in the field.

Have you tried Exiv ?

Exiv2 is a C++ library and a command line utility to manage image metadata. It provides fast and easy read and write access to the Exif, IPTC and XMP metadata of images in various formats. Exiv2 is available as free software and with a commercial license, and is used in many projects.

like image 85
Stéphane Avatar answered Nov 10 '22 11:11

Stéphane


There are different solutions. One is to define a structure (but make sure the field alignements are correct), then read the data, and use the structure to access the fields. Trivial example:

struct header {
    uint32_t len;
    unsigned char type;
    char name[16];
};

struct header hdr;

read(fd,&hdr,sizeof(hdr));

... access your fields using the structure ...

The topic is a bit more complex than this ;) But since you did not specified much more I think this still can help a bit.

like image 44
antirez Avatar answered Nov 10 '22 12:11

antirez