drewnoakes / metadata-extractor

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Apache License 2.0
2.56k stars 480 forks source link

How can extract all the Tiff Header/ Exif data into binary files. #444

Closed kingvhit closed 4 years ago

kingvhit commented 4 years ago

Hi,

Thank you very much for your library, it's very nice, easy to use. But I have a question about the metadata.

I have a project that needs an input of ExifData block following by the TIFF Header and need pass a byte array of Exifdata into this method -> exifData parameter

    /**
     * Add Exif data for the specified image. The data must be a valid Exif data block,
     * starting with "Exif\0\0" followed by the TIFF header (See JEITA CP-3451C Section 4.5.2.)
     *
     * @param imageIndex index of the image, must be a valid index for the max number of image
     *                   specified by {@link Builder#setMaxImages(int)}.
     * @param exifData byte buffer containing a Exif data block.
     * @param offset offset of the Exif data block within exifData.
     * @param length length of the Exif data block.
     */
    public void addExifData(int imageIndex, @NonNull byte[] exifData, int offset, int length) {
    }

In fact, I think your library is parsing the data from the Exif data block and then extract it into the readable data and convert it to Tag object.

But, now I want to get the Exif Data block as a byte array or write all metadata into the binary file. Can I do it in this library?

My idea is :

  1. Solution 1:

    • Create a new file with empty data (byte array)
    • Add "Exif\0\0" as the first of sequence. Then: I need to put some Tag data into the next sequence, but I don't know and not clear is it work or not. By using directory.getByteArray(TagName) to get data of its directory and then put it into sequence until the end of all tag.
  2. Solution 2: Get byte array data beginning of "Exif\0\0" and ending of Exif Data Block.

    • For the begin of Exif data -> very clear, I can detect that from files.
    • For the end of Exif data -> very confused, I have read some documents, but may it is different between file type, EXIF version, ...

Do you have any suggestions? Or how can I write the EXIF data into the HEIF file? Some library like Nokia HEIF is using Exif Data Block as byte array is a parameter input, so that why I need the Exif data as a byte array.

drewnoakes commented 4 years ago

Are you trying to read existing Exif data from a file and obtain it as a byte[]? Or are you trying to construct your own Exif data programmatically and save it out in Exif format?

If you're reading Exif from JPEG files it should be straightforward to obtain the byte arrays via JpegSegmentReader. You'll want to use JpegSegmentType.APP1 which usually contains Exif data. You may need to trim off the Exif\0\0 preamble to get the actual Exif data.

kingvhit commented 4 years ago

Hi @drewnoakes, I want to extract all the Exif data blocks into a binary file like data.exif . This file will begin from Exif\0\0 -> end of Exif block.

Also, I know the beginning of the EXIF data block is start from Exif\0\0 but I didn't know the ending of that block.

kingvhit commented 4 years ago

@drewnoakes : hi, any help? I have to try many methods but some of them not works.

drewnoakes commented 4 years ago

Sorry I missed this. Are you trying to read from JPEG? Please provide more information and I'll reopen this if you're still stuck. In general it's better to ask support questions on Stack Overflow, tagging them with metadata-extractor.

s3abiscuit commented 3 years ago

hi, I also want to use addExifData to add eixf info to heic with multiple images ,but I do not know how to form the input parameters "byte[] exifData", same with you, do you have any solusions? looking forward to your replay,thanks!

ashokkumar88 commented 9 months ago

@s3abiscuit @kingvhit Did you find any workaround? I need this too in one of my project.