Created
June 5, 2010 12:20
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding=utf-8 | |
""" | |
posterImageFromMovie.py, 2010 by Sven-S. Porst <[email protected]> | |
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