Reputation: 9
I am trying to get EXIF data from a mp4 file using exif-js with vain. My code is attached below.
Image part works fine, but video part does NOT.
https://github.com/exif-js/exif-js?tab=readme-ov-file According to the exif-js page, XMP is supported by calling EXIF.enableXmp();, I put it before a call to get EXIF data from a mp4 file.
As far as I know XMP is used for storing meta (like EXIF) data in video files. https://www.quora.com/What-is-the-equivalent-of-EXIF-for-videos-What-are-easy-ways-to-view-the-data
Any idea about how to fix the code?
Thank you very much!
Have a nice weekend :)
Warm Regards,
DoKtor.
Update: There seems it is not common to have "Make" and "Model" for meta data in videos, so I have just chosen GPS Latitude which seems more common both in jpg and mp4. exiftool outputs are added at the end. You can try this code: http://doc.uk.to/test/ and download the contents test.jpg and test.mp4 as well. These contents are actually taken by me by the way, please enjoy them :)
<!Doctype html>
<head>
<title> EXIF movies test </title>
</head>
<script src="https://cdn.jsdelivr.net/npm/exif-js"></script>
<script type=text/javascript>
window.onload=getExif;
function getExif() {
var img1 = document.getElementById("img1");
EXIF.getData(img1, function() {
var make = EXIF.getTag(this, "Make");
var model = EXIF.getTag(this, "Model");
var GpsLatitude = EXIF.getTag(this, "GPSLatitude");
var makeAndModel = document.getElementById("makeAndModel");
makeAndModel.innerHTML = `${make} ${model} ${GpsLatitude}`;
});
EXIF.enableXmp();
var img2 = document.getElementById("img2");
EXIF.getData(img2, function() {
var myData =this;
var make = "A"; //EXIF.getTag(this, "Make");
var model = "B"; //EXIF.getTag(this, "Model");
var GpsLatitude = EXIF.getTag(this, "GPSLatitude");
var makeAndModel2 = document.getElementById("makeAndModel2");
makeAndModel2.innerHTML = `${make} ${model} ${GpsLatitude}`;
var allMetaData = EXIF.getAllTags(this);
var allMetaDataSpan = document.getElementById("allMetaDataSpan");
allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, "\t");
});
}
</script>
<body>
<img width=400 src="test.jpg" id="img1" />
<pre>Make and model: <span id="makeAndModel"></span></pre>
<br/>
<!--<img src="test.mp4" id="img2" />-->
<!--
<video id="img2" autoplay muted width="560" height="315" controls >
<source src="test.mp4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></video>
-->
<iframe id= "img2" width="560" height="315" src="test.mp4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<pre>Make and model2: <span id="makeAndModel2"></span></pre>
<pre id="allMetaDataSpan"></pre>
<br/>
</body>
</html>
$ exiftool test.jpg | grep "GPS Latitude"
GPS Latitude Ref : South
GPS Latitude : 3 deg 8' 50.92" S
$ exiftool test.mp4 | grep "GPS Latitude"
GPS Latitude : 24 deg 19' 55.51" N
GPS Latitude Ref : North
Upvotes: 1
Views: 659
Reputation: 6174
No, both file's metadata formats differ:
exiftool -v2 http://doc.uk.to/test/test.jpg
produces the following output (irrelevant lines substituted with ...
):
JPEG APP1 (13812 bytes): ExifByteOrder = MM + [IFD0 directory with 14 entries] ... | 11) GPSInfo (SubDirectory) --> | - Tag 0x8825 (4 bytes, int32u[1]) | + [GPS directory with 4 entries] | | 0) GPSLatitudeRef = S | | - Tag 0x0001 (2 bytes, string[2]) | | 1) GPSLatitude = 3 8 50.9153713 (3/1 8/1 509153713/10000000) | | - Tag 0x0002 (24 bytes, rational64u[3]) | | 2) GPSLongitudeRef = E | | - Tag 0x0003 (2 bytes, string[2]) | | 3) GPSLongitude = 35 33 24.05090632 (35/1 33/1 2405090632/100000000) | | - Tag 0x0004 (24 bytes, rational64u[3]) ...
That means the JFIF file contains
APP1
segment which identifies as Exif.
IFD0
) 12th entry (counting starts with 0) points to a GPS directory,
exiftool -v2 http://doc.uk.to/test/test.mp4
produces:
... XMP (SubDirectory) --> - Tag 'uuid' (2883 bytes) + [XMP directory, 2867 bytes] | XMPToolkit = Image::ExifTool 12.76 | GPSLatitude = 24,19.92517515N | - Tag 'x:xmpmeta/rdf:RDF/rdf:Description/exif:GPSLatitude' | GPSLongitude = 123,56.41529555E | - Tag 'x:xmpmeta/rdf:RDF/rdf:Description/exif:GPSLongitude' ...
That means the ISO container has
uuid
atom which identifies as XMP,
Exif and XMP are two different formats - don't confuse every metadata format as Exif.
ExifTool has its name for historic reasons, because at first it really only wanted to support Exif, but now it can read many more formats, even propritary ones.
Exif.js claims:
A JavaScript library for reading EXIF meta data from image files.
Get it? Image files. No mention of video containers. And even that is wrong, as it only supports JFIF as picture format. From those, it can not only read Exif, but also XMP and IPTC. It doesn't even try to read from other file formats - not even other picture formats. And (like many) they write Exif wrongly in all uppercase. That library isn't worth much.
Upvotes: 1