def add(self, canvas_or_context): if self.movie is None: # The first frame will be written to a temporary png file, # then opened as a movie file, then saved again as a movie. handle, self.tmpfname = mkstemp('.tiff') canvas_or_context.save(self.tmpfname) try: movie, err = QTMovie.movieWithFile_error_(self.tmpfname) movie.setAttribute_forKey_(NSNumber.numberWithBool_(True), QTMovieEditableAttribute) range = QTMakeTimeRange(QTMakeTime(0, 600), movie.duration()) movie.scaleSegment_newDuration_(range, self._time) if err is not None: raise str(err) movie.writeToFile_withAttributes_(self.fname, {QTMovieFlatten: True}) self.movie, err = QTMovie.movieWithFile_error_(self.fname) self.movie.setAttribute_forKey_(NSNumber.numberWithBool_(True), QTMovieEditableAttribute) if err is not None: raise str(err) self.imageTrack = self.movie.tracks()[0] finally: os.remove(self.tmpfname) else: try: canvas_or_context.save(self.tmpfname) img = NSImage.alloc().initByReferencingFile_(self.tmpfname) self.imageTrack.addImage_forDuration_withAttributes_( img, self._time, {QTAddImageCodecType: 'tiff'}) finally: try: os.remove(self.tmpfname) except OSError: pass self.frame += 1
def add(self, canvas_or_context): if self.movie is None: # The first frame will be written to a temporary png file, # then opened as a movie file, then saved again as a movie. handle, self.tmpfname = mkstemp(".tiff") canvas_or_context.save(self.tmpfname) try: movie, err = QTMovie.movieWithFile_error_(self.tmpfname, None) movie.setAttribute_forKey_(NSNumber.numberWithBool_(True), QTMovieEditableAttribute) range = QTMakeTimeRange(QTMakeTime(0, 600), movie.duration()) movie.scaleSegment_newDuration_(range, self._time) if err is not None: raise str(err) movie.writeToFile_withAttributes_(self.fname, {QTMovieFlatten: True}) self.movie, err = QTMovie.movieWithFile_error_(self.fname, None) self.movie.setAttribute_forKey_(NSNumber.numberWithBool_(True), QTMovieEditableAttribute) if err is not None: raise str(err) self.imageTrack = self.movie.tracks()[0] finally: os.remove(self.tmpfname) else: try: canvas_or_context.save(self.tmpfname) img = NSImage.alloc().initByReferencingFile_(self.tmpfname) self.imageTrack.addImage_forDuration_withAttributes_(img, self._time, {QTAddImageCodecType: "tiff"}) finally: try: os.remove(self.tmpfname) except OSError: pass self.frame += 1
def movie_maker(movdir, imgdir, timeval, timescale, ih): print('making movie %s' % ih) imgpaths = glob.glob(os.path.join(imgdir, 'ocean_his_*_%s.png' % ih)) imgpaths.sort() movpath = os.path.join(movdir, '%s.mov' % ih) '''I am creating a new image sequence (QuickTime movie).''' mov, err = QTMovie.alloc().initToWritableFile_error_(movpath, None) if mov == None: errmsg = 'Could not create movie file: %s' % (movpath) raise IOError, errmsg duration = QTMakeTime(timeval, timescale) # you can also use "tiff" # attrs = {QTAddImageCodecType: 'avc1'}#, QTAddImageCodecQuality: codecHighQuality} attrs = {QTAddImageCodecType: 'avc1'} for imgpath in imgpaths: # img = NSImage.alloc().initWithContentsOfFile_(imgpath) img = NSImage.alloc().initByReferencingFile_(imgpath) mov.addImage_forDuration_withAttributes_(img, duration, attrs) del (img) print('Writing movie %s' % ih) mov.updateMovieFile()
def movie_maker(movdir,imgdir,timeval,timescale,ih): print('making movie %s' % ih) imgpaths = glob.glob(os.path.join(imgdir,'ocean_his_*_%s.png'%ih)) imgpaths.sort() movpath = os.path.join(movdir,'%s.mov' %ih ) '''I am creating a new image sequence (QuickTime movie).''' mov, err = QTMovie.alloc().initToWritableFile_error_(movpath, None) if mov == None: errmsg = 'Could not create movie file: %s' % (movpath) raise IOError, errmsg duration = QTMakeTime(timeval, timescale) # you can also use "tiff" # attrs = {QTAddImageCodecType: 'avc1'}#, QTAddImageCodecQuality: codecHighQuality} attrs = {QTAddImageCodecType: 'avc1'} for imgpath in imgpaths: # img = NSImage.alloc().initWithContentsOfFile_(imgpath) img = NSImage.alloc().initByReferencingFile_(imgpath) mov.addImage_forDuration_withAttributes_(img, duration, attrs) del(img) print('Writing movie %s' %ih) mov.updateMovieFile()
def updateVideoSource(self, url): if self.video_initialized: video_source = QTMovie.alloc().initWithFile_(url) self.videoView.setMovie_(video_source)
def initVideoSource(self, url='/System/Library/Compositions/Sunset.mov'): if not self.video_initialized: video_source = QTMovie.alloc().initWithFile_(url) self.videoView.setMovie_(video_source) self.video_initialized = True