Skip to content

Instantly share code, notes, and snippets.

@ssp
Created June 5, 2010 12:20
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 ssp/426581 to your computer and use it in GitHub Desktop.
Save ssp/426581 to your computer and use it in GitHub Desktop.
Use QTKit and PyObjC to get a JPEG for an image's poster frame.
#!/usr/bin/env python
#coding=utf-8
"""
posterImageFromMovie.py, 2010 by Sven-S. Porst <ssp-web@earthlingsoft.net>
Uses PyObjC to extract the poster frame from a movie file and save it as a JPEG next to the movie. An existing file moviename.jpeg will be overwritten.
"""
from QTKit import *
import sys
import os
if len(sys.argv) == 2:
path = NSString.stringWithString_(os.path.realpath(sys.argv[1]))
movie, error = QTMovie.movieWithFile_error_(path, None)
if movie != None:
image = movie.posterImage()
imagerep = image.representations()[0]
data = imagerep.representationUsingType_properties_(NSJPEGFileType, None)
if data != None:
destinationPath = path.stringByDeletingPathExtension().stringByAppendingString_(".jpeg")
result = data.writeToFile_atomically_(destinationPath, True)
if result == False:
print "Could not write JPEG file."
else:
print "Could not retrieve poster frame image data."
else:
print "Could not open movie file."
else:
print "Please specify exactly one path to a movie file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment