Skip to content

Instantly share code, notes, and snippets.

@oparrish
Last active December 29, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oparrish/7694368 to your computer and use it in GitHub Desktop.
Save oparrish/7694368 to your computer and use it in GitHub Desktop.
Output the duration for an M4A
#!/usr/local/bin/python
import sys
from mutagen.mp4 import MP4
m4a_file = sys.argv[1]
m4a = MP4(m4a_file)
length_secs = m4a.info.length
hours = int(length_secs / 60 / 60)
minutes = int(length_secs / 60) - hours * 60
seconds = int(length_secs - minutes * 60 - hours * 3600)
print("{:02}:{:02}:{:02}".format(hours,minutes,seconds))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment