Skip to content

Instantly share code, notes, and snippets.

@qihnus
Last active December 13, 2020 12:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qihnus/3099310 to your computer and use it in GitHub Desktop.
Save qihnus/3099310 to your computer and use it in GitHub Desktop.
List video durations on a Mac
#!/usr/bin/env python
import os
import sys
import glob
from QTKit import QTMovie
TOTAL_DURATION = 0
def format_duration(duration):
return "%5d:%02d" % (duration / 60, duration % 60)
def process(fn):
global TOTAL_DURATION
attributes = {'QTMovieFileNameAttribute': os.path.abspath(fn)}
movie, error = QTMovie.movieWithAttributes_error_(attributes, None)
if error or not movie:
print error.description()
return
duration = movie.duration()[0]/movie.duration()[1]
TOTAL_DURATION += duration
print format_duration(TOTAL_DURATION), format_duration(duration), fn
def main(files):
for fn in files:
process(fn)
if __name__ == '__main__':
if len(sys.argv) > 1:
main(sys.argv[1:])
else:
main("*.mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment