Read/Write file metadata using C/C++

17,402

Solution 1

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.

Solution 2

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.

Share:
17,402

Related videos on Youtube

Rajendra Uppal
Author by

Rajendra Uppal

Updated on April 21, 2022

Comments

  • Rajendra Uppal
    Rajendra Uppal about 2 years

    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.

  • Rajendra Uppal
    Rajendra Uppal about 14 years
    Don't want to use any library. Thanks for the information about the library anyway.
  • Rajendra Uppal
    Rajendra Uppal about 14 years
    Thanks for the structure. But you realize yourself that it's not that simple!
  • Hey
    Hey about 8 years
    Hi, does Exif have an equivalent in C ? It seems like it has only a C++ API.
  • Admin
    Admin almost 5 years
    Create the structure its simple, the hard part you have not done, get the information.