Read, write, copy files metadata with ExifTool (page 2)

botond published 2019/06/15, Sat - 16:40 time

2. page content

 

Continuation

Az on the first page we got to know that exiftool command and its basic reading capabilities. On this page, we will expand our knowledge with the write and copy operations of the metadata program, and we will try the command with other file formats through even more quick examples.

 

 

Basic Uses

Writing

Writing metadata is done with the exiftool command in the same way as reading, except that the tags need to be given their own value. There are several ways to do the writing operation, depending on what you want to accomplish:

assignment

In this case, you simply enter a value for the tag you want with an equal sign:

exiftool -[csoport:]Mezőnév=<érték> <képfájl neve>

Same with one specific example:

exiftool -Headline="Kép címe" proba_php.jpg

And the result is shown in the following pictures, where there was no "Headline" tag in the image file before:

addition

The add function allows you to do the following:

  • Add an item to a list type item
  • Increase date / time type values ​​(eg time stamps)
  • Increase the value of numeric type tags

The syntax is as follows:

exiftool -[csoport:]Mezőnév+=<érték> <képfájl neve>

The group can be, for example, EXIF, IPTC, XMP, etc. Optional. If you do not specify a group name and the member exists in more than one group, it will update the tag with the given field name in each group.

Example of increasing the numeric value:

 

miscarry

I did not intentionally use the name subtraction here because this function cannot be used to extract general numeric values ​​of meta tags, but can be used for:

  • Remove an item from a list type item
  • Decrease date / time type values ​​(eg time stamps)
  • Delete the value of a member if the exact value is specified

syntax:

exiftool -[csoport:]Mezőnév-=<érték> <képfájl neve>

Groups work the same way as when you add them, they are optional.

Example of deleting a value field by specifying the exact value:

In this example, we first give a text value to a tag and then check it back. Then we try to take another value from it, which fails. Finally, by specifying the exact value, we succeed in deleting the tag value.

In essence, we could have used the following command instead:

exiftool -Description-= proba_php.jpg

Where nothing is given after the equal sign. In this case, it also deletes the value. The difference is that subtraction with the exact value can be used for conditional deletion, for example in an automation script, where we delete only the value (s) that exactly match the one we specified, or delete it only if the specified value.

Copying

You can also use the exiftool command to copy metadata from one file to another file, or to multiple files. It has the following syntax:

exiftool -tagsFromFile <forrás fájl> [-forrás tag[>cél tag]...] <cél fájl>

Switches, parameters:

  • -tagsFromFile: You will then need to specify the source file to which you want to copy the metadata.
  • source tag: Optional. If specified, only the specified member or group (eg EXIF, IPTC, XMP, GPS, etc.) will be copied.
  • > target member: If the source member is specified, here - also optionally - you can specify in which tag file or group to save the data read from the source. Of course, the source and destination data formats must match.
  • target file: You must specify at least one file where you enter the appropriate metadata. For multiple files, overwrites the same data in each.

Let's try the copy function in action.

In the following example, one member of one jpg file is uploaded with a value and copied to another jpg file:

Finally, by listing all the metadata of the target file, the value set in the other field in the Description field will be displayed, as well as the change timestamps for the file to the current one.

By default, the copy function backs up the original file as you write saved as .original in the same directory as the destination file. If you do not want backups, use -overwrite_original switch.

 

 

Quick examples

In this section, we will review a few more short examples, try the exiftool command with some other file formats.

For the examples below, I used my own files, so other files may have field or value differences.

Read GPS data

Even with jpg files, if you need GPS data for a photo, you can retrieve all GPS related tagfor standard GPS data:

exiftool -GPS:all <képnév>

However, your imaging device may not store GPS metadata in the jpg file by default and may not be able to extract all the fields from the GPS group. In this case, instead of group filtering, we can use grep to read all the GPS data.

And the output is in a file created with my phone:

Read EPS files

You can also read a lot of useful information from EPS vector files, including the name of the authoring software, the resolution of the drawing board, the number of drawing boards, the color space of the graphics, etc.:

exiftool \
    -CreatorTool \
    -ImageSize \
    -Pages \
    -SwatchColorantMode \
    vektorfajl.eps

The output of this is an EPS file I created:

Creator Tool                    : Adobe Illustrator CC 23.0 (Windows)
Image Size                      : 600x601
Pages                           : 1
Swatch Colorant Mode            : RGB, RGB, RGB, RGB, RGB, RGB, RGB, RGB, RGB

Reading ZIP files

I've compressed some files with Total Commander and read out their metadata:

exiftool tomoritett.zip

The zip file does not contain too much metadata, with the following output:

ExifTool Version Number         : 10.40
File Name                       : tomoritett.zip
Directory                       : .
File Size                       : 916 kB
File Modification Date/Time     : 2019:06:07 14:46:50+02:00
File Access Date/Time           : 2019:06:07 14:46:50+02:00
File Inode Change Date/Time     : 2019:06:07 14:47:01+02:00
File Permissions                : rw-r--r--
File Type                       : ZIP
File Type Extension             : zip
MIME Type                       : application/zip
Zip Required Version            : 20
Zip Bit Flag                    : 0x0802
Zip Compression                 : Deflated
Zip Modify Date                 : 2019:06:07 14:11:10
Zip CRC                         : 0x36c718d5
Zip Compressed Size             : 57736
Zip Uncompressed Size           : 66726
Zip File Name                   : exiftool-gps-adatok-kiolvasasa.png

There are useful things in it, such as the uncompressed size of the content, which can be useful if you want to use a script to calculate the uncompressed size of zip files in a directory.

Gzip compression may include other fields.

Read AVI video files

You can also read useful things from avi video files such as framerate, video codes, resolution, color depth, compression algorithm, audio sampling rate, audio coding, number of audio channels, etc.

Example with a custom AVI file:

exiftool \
    -FrameRate \
    -VideoCodec \
    -ImageWidth \
    -ImageHeight \
    -BitDepth \
    -Compression \
    -AudioSampleRate \
    -Encoding \
    -NumChannels \
    video.avi
Frame Rate                      : 25
Video Codec                     : XVID
Image Width                     : 720
Image Height                    : 388
Bit Depth                       : 24
Compression                     : XVID
Audio Sample Rate               : 32000
Encoding                        : MP3
Num Channels                    : 2

Read MP3 music files

From our MP3 music files, you can read, among other things, the audio bandwidth, sampling frequency, channel mode, year, genre, album name, artist, song title, playing time, etc. My example:

exiftool \
    -AudioBitrate \
    -SampleRate \
    -ChannelMode \
    -Year \
    -Genre \
    -Album \
    -Artist \
    -Title \
    -Duration \
    Brian_Tyler_-_Rambo_Soundtrack_-_01_-_Rambo_Theme.mp3
Audio Bitrate                   : 128 kbps
Sample Rate                     : 44100
Channel Mode                    : Joint Stereo
Year                            : 2008
Genre                           : Soundtrack
Album                           : Rambo Soundtrack
Artist                          : Brian Tyler
Title                           : Rambo Theme
Duration                        : 0:03:27 (approx)

But if only that ID3 tagwe are curious to read it:

exiftool -ID3:all Brian_Tyler_-_Rambo_Soundtrack_-_01_-_Rambo_Theme.mp3
Publisher                       : 
Comment                         : 
Track                           : 1
Year                            : 2008
Genre                           : Soundtrack
Album                           : Rambo Soundtrack
Artist                          : Brian Tyler
Title                           : Rambo Theme

 

 

Read PDF documents

You can read many things from a PDF file saved in Photoshop, including a few:

exiftool \
    -PDFVersion \
    -CreatorTool \
    -ColorMode \
    -ICCProfileName \
    -PageCount \
    -XResolution \
    -YResolution \
    -ResolutionUnit \
    -Orientation \
    -ColorSpace \
    -ExifImageWidth \
    -ExifImageHeight \
    -Compression \
    metaadatok-kezelese-az-exiftool-programmal.pdf

The output of this is:

PDF Version                     : 1.7
Creator Tool                    :  Adobe Photoshop CS5 Windows
Color Mode                      : RGB
ICC Profile Name                : sRGB IEC61966-2.1
Page Count                      : 1
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Orientation                     : Horizontal (normal)
Color Space                     : sRGB
Exif Image Width                : 1200
Exif Image Height               : 630
Compression                     : JPEG (old-style)

 

In the examples I did not list queries for each field, much more information is available for each file type. Here, I only highlighted the more important ones for the sake of the example. You can get the full list by running exiftool without filter switches.

 

A next page we continue to build a complete automation shell script ...

 

 

Navigation

This description consists of several pages: