Edit Custom Metadata on a JPG file - Live Photo

403 Views Asked by At

I am trying to edit a custom metadata value of a JPG file (static image of a Live Photo created by iPhone). Tried the exiftool but it doesnt work for me.

For reference this is the metadata of one of the file - https://www.metadata2go.com/result/93287b28-1c16-4491-affe-8ffbd6d9dd1a

the field I would like to edit and update is

Content Identifier DF64C2AE-ED3C-4778-BFCA-C15277E521D2

I tried updating the field with exiftool

exiftool -ContentIdentifier=5A0FFB8D-5410-4464-A343-61AE4A6C1109 LW16.jpg

It always throw error like file cannot be read or Warning: Tag 'ContentIdentifier' is not defined Nothing to do.

Anyone can help me with this or guide me with another method to change the value ?

1

There are 1 best solutions below

1
On

Im writing raw MakerNote to exif data using little_exif like this and it is working for now:) Im trying to work on the video part

use std::{
    fs,
    path::{Path, PathBuf},
};

use little_exif::{exif_tag, metadata::Metadata};

pub fn generate_binding() -> (String, Vec<u8>) {
    let uuid: String = uuid::Uuid::new_v4().into();
    let mut note:Vec<u8> = b"Apple iOS\x00\x00\x01MM\x00\x01\x00\x11\x00\x02\x00\x00\x00\x25\x00\x00\x00\x20\x00\x00\x00\x00".to_vec();
    // let note = header + uuid.as_bytes().to_vec() + vec![b"\x00\x00\x00\x00"];
    note.extend(uuid.as_bytes().to_vec());
    note.extend(b"\x00".to_vec());
    (uuid, note)
}

pub fn generate_live_photo(
    jpeg_src: &Path,
    mov_src: &Path,
    dest_dir: Option<&Path>,
) -> Option<(PathBuf, PathBuf)> {
    let (uuid, note) = generate_binding();
    let (jpeg, mov) = match dest_dir {
        Some(dest_dir) => {
            let (jpeg, mov) = (
                Path::new(dest_dir).join(match jpeg_src.file_name() {
                    Some(src) => src,
                    None => return None,
                }),
                Path::new(dest_dir).join(format!("{}.mov",uuid.to_uppercase())),
            );
            //copy files
            fs::copy(jpeg_src, &jpeg).unwrap();
            fs::copy(mov_src, &mov).unwrap();
            (jpeg, mov)
        }
        None => (jpeg_src.to_path_buf(), mov_src.join(uuid)),
    };

    let mut metadata = match Metadata::new_from_path(&jpeg) {
        Ok(data) => data,
        Err(_) => return None,
    };
    metadata.set_tag(exif_tag::ExifTag::MakerNote(note));
    match metadata.write_to_file(&jpeg) {
        Ok(_) => {}
        Err(_) => {
            return None;
        }
    };

    Some((jpeg, mov))
}