For video metadata, use ffmpeg
as Martin Drohmann says.
For image metadata (called "EXIF"):
OpenCV will discard image metadata; for instance, cv2.imread('bear.jpg')
will produce a 3-dimensional numpy array of pixel intensities (the third dimension being the R,G,B channels).
So to extract EXIF data, you can use an alternative image processing library for Python, which is very popular, called pillow
.
First, on the command line, install pillow: pip install pillow
.
Then you can extract EXIF data from bear.jpg
:
import PIL.Image
from PIL.ExifTags import TAGS
from pprint import pprint
image = PIL.Image.open('bear.jpg')
# Get the exif data and map to the correct tags
exif_data = {
PIL.ExifTags.TAGS[k]: v
for k,v in image._getexif().items()
if k in PIL.ExifTags.TAGS
}
pprint(exif_data)
Which will display the EXIF data:
{'ExposureBiasValue': (0, 3),
'ExposureTime': (1, 40),
'FNumber': (280, 100),
'ISOSpeedRatings': 100,
...
}
For complete information on EXIF, see https://exiv2.org/tags.html.