[Python] How to read exif data of movies in Python?

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    I use exifread (installed with python3 -m pip install exifread) to read EXIF tags from photos. The same camera takes videos with extension .MOV and a Create Date EXIF field that I am able to view with exiftool (installed with brew install exiftool):


    $ exiftool DSC_0002.MOV | grep Date
    File Modification Date/Time : 2020:02:20 18:13:14+00:00
    File Access Date/Time : 2020:03:07 08:11:57+00:00
    File Inode Change Date/Time : 2020:03:04 11:24:51+00:00
    Modify Date : 2020:02:20 18:13:21
    Track Create Date : 2020:02:20 18:13:21
    Track Modify Date : 2020:02:20 18:13:21
    Media Create Date : 2020:02:20 18:13:21
    Media Modify Date : 2020:02:20 18:13:21
    Create Date : 2020:02:20 18:13:15
    Date/Time Original : 2020:02:20 18:13:15
    Date Display Format : Y/M/D


    I suppose exifread was built for photos, as the code below shows an empty list of tags for this video:

    import exifread

    f = open("/path/to/file", "rb")
    tags = exifread.process_file(f)
    print(tags)


    One solution is to make a subprocess call to exiftool and parse the result:

    EXIFTOOL_DATE_TAG_VIDEOS = "Create Date"
    EXIF_DATE_FORMAT = "%Y:%m:%d %H:%M:%S"

    cmd = "exiftool '%s'" % filepath
    output = subprocess.check_output(cmd, shell=True)
    lines = output.decode("ascii").split("\n")
    for l in lines:
    if EXIFTOOL_DATE_TAG_VIDEOS in l:
    datetime_str = l.split(" : ")[1]
    print(datetime.datetime.strptime(datetime_str,
    EXIF_DATE_FORMAT))


    How can I access the list of EXIF tags without a subprocess call?

    Continue reading...

Compartilhe esta Página