1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
* Nom-Exif
[[https://github.com/mindeng/nom-exif/actions/workflows/rust.yml/badge.svg][nom-exif workflow]]
Exif/metadata parsing library written in pure Rust with [[https://github.com/rust-bakery/nom][nom]].
** Supported File Types
- Images
- JPEG
- HEIF/HEIC
- Videos
- MOV
- MP4
** Features
- Zero-copy when appropriate :: Use borrowing and slicing instead of copying
whenever possible.
- Minimize I/O operations :: When metadata is stored at the end of a larger file
(such as a MOV file), ~Seek~ rather than ~Read~ to quickly locate the location of
the metadata.
- Pay as you go :: When extracting Exif data, only the information corresponding
to the specified Exif tags are parsed to reduce the overhead when processing a
large number of files.
** Usage
*** Parse Exif from Images
#+begin_src rust
use nom_exif::*;
use nom_exif::ExifTag::*;
use std::fs::File;
use std::path::Path;
use std::collections::HashMap;
let f = File::open(Path::new("./testdata/exif.jpg")).unwrap();
let exif = parse_jpeg_exif(f).unwrap().unwrap();
assert_eq!(
exif.get_value(&ImageWidth).unwrap(),
Some(IfdEntryValue::U32(3072)));
assert_eq!(
exif.get_values(&[CreateDate, ModifyDate, DateTimeOriginal]),
[
(&CreateDate, "2023:07:09 20:36:33"),
(&ModifyDate, "2023:07:09 20:36:33"),
(&DateTimeOriginal, "2023:07:09 20:36:33"),
]
.into_iter()
.map(|x| (x.0, x.1.into()))
.collect::<HashMap<_, _>>()
);
#+end_src
*** Parse metadata from Videos
#+begin_src rust
use nom_exif::*;
use std::fs::File;
use std::path::Path;
let f = File::open(Path::new("./testdata/meta.mov")).unwrap();
let entries = parse_mov_metadata(reader).unwrap();
assert_eq!(
entries
.iter()
.map(|x| format!("{x:?}"))
.collect::<Vec<_>>()
.join("\n"),
r#"("com.apple.quicktime.make", Text("Apple"))
("com.apple.quicktime.model", Text("iPhone X"))
("com.apple.quicktime.software", Text("12.1.2"))
("com.apple.quicktime.location.ISO6709", Text("+27.1281+100.2508+000.000/"))
("com.apple.quicktime.creationdate", Text("2019-02-12T15:27:12+08:00"))"#
);
#+end_src
|