Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mp4 metadata extraction in Python

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?

like image 830
TerraCode Avatar asked Oct 27 '25 17:10

TerraCode


1 Answers

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')
like image 173
salomonderossi Avatar answered Oct 29 '25 05:10

salomonderossi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!