I'm looking to use exiftool to scan the EXIF tags from my photos and videos. It's a perl executable. What's the best way to inferface with this? Are there any Python libraries to do this already? Or should I directly call the executable and parse the output? (The latter seems dirty.) Thanks.
The reason I ask is this because I am currently using pyexiv2, which does not have support for videos. Perl's exiftool has very broad support for images and videos, and I'd like to use it.
To avoid launching a new process for each image, you should start
exiftool
using the-stay_open
flag. You can then send commands to the process via stdin, and read the output on stdout. ExifTool supports JSON output, which is probably the best option for reading the metadata.Here's a simple class that launches an
exiftool
process and features anexecute()
method to send commands to that process. I also includedget_metadata()
to read the metadata in JSON format:This class is written as a context manager to ensure the process is exited if you are done. You can use it as
EDIT for python 3: To get this to work in python 3 two small changes are needed. The first is an additional argument to
subprocess.Popen
:The second is that you have to decode the byte series returned by
os.read()
:EDIT for Windows: To get this working on Windows, the
sentinel
need to be changed into"{ready}\r\n"
, i.e.Otherwise the program will hang because the while loop inside execute() won't stop