mp4 metadata extraction in Python

10,800

You could use the mp4file module for this.

pip install mp4file

Example from here

from mp4file.mp4file import Mp4File

def find_metadata_atom(file, name):
    atom = file.find('.//%s//data' % name)
    return atom.get_attribute('data')

file = Mp4File("bill.mp4")

title = find_metadata_atom(file, 'title')
tvshow = find_metadata_atom(file, 'tvsh')
Share:
10,800
TerraCode
Author by

TerraCode

Currently an intern at a research company. Looking to get into the game-industry as an artist.

Updated on June 04, 2022

Comments

  • TerraCode
    TerraCode almost 2 years

    I have a program that has to edit several videos based off of data in a separate json-file. These videos are sequential and they have metadata in their own json file. The program edits them with a frame-by-frame overlay (eye-tracking data).

    What I'd like to do is compare individual mp4 metadata with the json-file metadata so I can compare timestamps, making sure everything is synchronized.

    If possible, how would I get to the mp4 metadata?

  • TerraCode
    TerraCode about 8 years
    Works in theory, but the people who wrote the system for the "grouped" metadata didn't actually give me relevant data. Just found that out. Thanks for the response. I think I'll just load the entire batch in and work from there.
  • salomonderossi
    salomonderossi about 8 years
    @TerraCode I see. Sorry to hear that. If you think the answer might be usefull for others, I would appreciate a upvote or accept. If not, no offence ;)
  • Endlisnis
    Endlisnis about 3 years
    When I run your code, I get ModuleNotFoundError: No module named 'atom' And if I install atom, I then get: ImportError: cannot import name 'parse_atoms' from 'atom' (/home/rolf/.local/lib/python3.8/site-packages/atom/__init__‌​.py)
  • jmb2341
    jmb2341 over 2 years
    @Endlisnis I think this was written with python2