def _test(): import img import MacOS Qt.EnterMovies() fss, ok = macfs.PromptGetFile('Video to convert') if not ok: sys.exit(0) path = fss.as_pathname() url = urllib.pathname2url(path) rdr = reader(url) if not rdr: sys.exit(1) dstfss, ok = macfs.StandardPutFile('Name for output folder') if not ok: sys.exit(0) dstdir = dstfss.as_pathname() num = 0 os.mkdir(dstdir) videofmt = rdr.GetVideoFormat() imgfmt = videofmt.getformat() imgw, imgh = videofmt.getsize() timestamp, data = rdr.ReadVideo() while data: fname = 'frame%04.4d.jpg' % num num = num + 1 pname = os.path.join(dstdir, fname) print 'Writing', fname, imgw, imgh, len(data) ## wrt = img.writer(imgfmt, pname) ## wrt.width = imgw ## wrt.height = imgh ## wrt.write(data) timestamp, data = rdr.ReadVideo() ## MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG') if num > 20: break print 'Total frames:', num
def __init__(self, name, attrdict, scheduler, ui): ChannelWindowAsync.__init__(self, name, attrdict, scheduler, ui) if debug: print 'VideoChannel: init', name self.arm_movie = None self.play_movie = None self.has_callback = 0 self.idleprocactive = 0 self._paused = 0 if QT_AVAILABLE: Qt.EnterMovies() self.DBGcolor = (0xffff, 0, 0) self.__rc = None self.__extra_end_delay = 0 self.__qid = None
def get(url): if not Qt: print 'QuickTime not available, cannot obtain movie duration' return 0 try: filename = MMurl.urlretrieve(url)[0] except IOError: return 0 Qt.EnterMovies() try: movieResRef = Qt.OpenMovieFile(filename, 1) except (ValueError, Qt.Error), arg: print 'Cannot open QT movie:', filename, arg return 0
def _test(): import EasyDialogs try: from PIL import Image except ImportError: Image = None import MacOS Qt.EnterMovies() path = EasyDialogs.AskFileForOpen(message='Video to convert') if not path: sys.exit(0) rdr = reader(path) if not rdr: sys.exit(1) dstdir = EasyDialogs.AskFileForSave(message='Name for output folder') if not dstdir: sys.exit(0) num = 0 os.mkdir(dstdir) videofmt = rdr.GetVideoFormat() imgfmt = videofmt.getformat() imgw, imgh = videofmt.getsize() timestamp, data = rdr.ReadVideo() while data: fname = 'frame%04.4d.jpg' % num num = num + 1 pname = os.path.join(dstdir, fname) if not Image: print 'Not', print 'Writing %s, size %dx%d, %d bytes' % (fname, imgw, imgh, len(data)) if Image: img = Image.fromstring('RGBA', (imgw, imgh), data) img.save(pname, 'JPEG') timestamp, data = rdr.ReadVideo() MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG') if num > 20: print 'stopping at 20 frames so your disk does not fill up:-)' break print 'Total frames:', num return
def main(): # skip the toolbox initializations, already done # XXXX Should use gestalt here to check for quicktime version Qt.EnterMovies() # Get the movie file if len(sys.argv) > 1: filename = sys.argv[1] else: filename = EasyDialogs.AskFileForOpen() # Was: QuickTime.MovieFileType if not filename: sys.exit(0) # Open the window bounds = (175, 75, 175 + 160, 75 + 120) theWindow = Win.NewCWindow(bounds, os.path.split(filename)[1], 1, 0, -1, 0, 0) Qd.SetPort(theWindow) # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil) playMovieInWindow(theWindow, filename, theWindow.GetWindowPort().GetPortBounds())
def EnterMovies(): global _moviesinitialized if not _moviesinitialized: Qt.EnterMovies() _moviesinitialized = 1
def main(): print 'hello world' # XXXX # skip the toolbox initializations, already done # XXXX Should use gestalt here to check for quicktime version Qt.EnterMovies() # Get the movie file fss = EasyDialogs.AskFileForOpen( wanted=File.FSSpec) # Was: QuickTime.MovieFileType if not fss: sys.exit(0) # Open the window bounds = (175, 75, 175 + 160, 75 + 120) theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0) # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil) Qd.SetPort(theWindow) # Get the movie theMovie = loadMovie(fss) # Relocate to (0, 0) bounds = theMovie.GetMovieBox() bounds = 0, 0, bounds[2] - bounds[0], bounds[3] - bounds[1] theMovie.SetMovieBox(bounds) # Create a controller theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie) # Get movie size and update window parameters rv, bounds = theController.MCGetControllerBoundsRect() theWindow.SizeWindow(bounds[2], bounds[3], 0) # XXXX or [3] [2]? Qt.AlignWindow(theWindow, 0) theWindow.ShowWindow() # XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds) theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1') # XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow) done = 0 while not done: gotone, evt = Evt.WaitNextEvent(0xffff, 0) (what, message, when, where, modifiers) = evt ## print what, message, when, where, modifiers # XXXX if theController.MCIsPlayerEvent(evt): continue if what == Events.mouseDown: part, whichWindow = Win.FindWindow(where) if part == Windows.inGoAway: done = whichWindow.TrackGoAway(where) elif part == Windows.inDrag: Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000)) elif what == Events.updateEvt: whichWindow = Win.WhichWindow(message) if not whichWindow: # Probably the console window. Print something, hope it helps. print 'update' else: Qd.SetPort(whichWindow) whichWindow.BeginUpdate() Qd.EraseRect(whichWindow.GetWindowPort().GetPortBounds()) whichWindow.EndUpdate()
from Carbon import Qt
def readFrame(inputMovieName, outputImageName, frameNumber): try: os.unlink(outputImageName) # delete the existing outputImageName, if it exists except: pass try: Qt.EnterMovies() fd = Qt.OpenMovieFile(inputMovieName, 0) movie, junk1, junk2 = Qt.NewMovieFromFile(fd, 0, 0) try: videotrack = movie.GetMovieIndTrackType(1, QuickTime.VisualMediaCharacteristic, QuickTime.movieTrackCharacteristic) videomedia = videotrack.GetTrackMedia() except Qt.Error: videotrack = videomedia = None if videotrack: x0, y0, x1, y1 = movie.GetMovieBox() width, height = x1-x0, y1-y0 old_port, old_dev = Qdoffs.GetGWorld() try: movie_rect = (0, 0, width, height) gworld = Qdoffs.NewGWorld(32, movie_rect, None, None, QDOffscreen.keepLocal) pixmap = gworld.GetGWorldPixMap() Qdoffs.LockPixels(pixmap) Qdoffs.SetGWorld(gworld.as_GrafPtr(), None) Qd.EraseRect(movie_rect) movie.SetMovieGWorld(gworld.as_GrafPtr(), None) movie.SetMovieBox(movie_rect) movie.SetMovieActive(1) movie.MoviesTask(0) movie.SetMoviePlayHints(QuickTime.hintsHighQuality, QuickTime.hintsHighQuality) finally: Qdoffs.SetGWorld(old_port, old_dev) # finished with Quicktime initialization QTSearchFlags = QuickTime.nextTimeMediaSample|QuickTime.nextTimeEdgeOK startTime, frameDuration = videomedia.GetMediaNextInterestingTime(QTSearchFlags, 0, 1.0) # startTime is time at start of movie (start offset) # frameDuration is the number of video time units that pass each frame (in videotimescale units) if debug: print "frameDuration", frameDuration movieDuration = videotrack.GetTrackDuration() # in movietimescale units if debug: print "movieDuration", movieDuration movietimescale = movie.GetMovieTimeScale() if debug: print "movietimescale", movietimescale videotimescale = videomedia.GetMediaTimeScale() if debug: print "videotimescale", videotimescale movieDurationSeconds = float(movieDuration) / movietimescale if debug: print "movieDurationSeconds", movieDurationSeconds frameLengthSeconds = float(frameDuration) / videotimescale if debug: print "frameLengthSeconds", frameLengthSeconds, "(inverse)", 1.0/frameLengthSeconds totalFrames = movieDurationSeconds / frameLengthSeconds if debug: print "totalFrames", totalFrames, "(rounded)", int(round(totalFrames)) frames = int(round(totalFrames)) if debug: print "reading frame", frameNumber, "at videotime", startTime+frameNumber*frameDuration timestamp = videomedia.GetMediaNextInterestingTimeOnly(QTSearchFlags, startTime+frameNumber*frameDuration, 1) if timestamp < 0: raise "Quicktime error", "error %s, frame search failed at videotime %s" % (timestamp,startTime+frameNumber*frameDuration) moviecurtime, junk1, junk2 = Qt.ConvertTimeScale((timestamp, videotimescale, None), movietimescale) # I don't know why this time adjustment is needed, but it sometimes seeks to the wrong frame without it movieframetime, junk1, junk2 = Qt.ConvertTimeScale((frameDuration, videotimescale, None), movietimescale) if debug: print "movieframetime", movieframetime if movieframetime > 1: moviecurtime += 1 movie.SetMovieTimeValue(moviecurtime) movie.MoviesTask(0) # shuffle the offscreen PixMap data, because it may have funny stride values and alpha channel rowbytes = Qdoffs.GetPixRowBytes(pixmap) start = 0 rv = [] for i in range(height): nextline = Qdoffs.GetPixMapBytes(pixmap, start, width*4) for j in range(width): rgb = nextline[4*j+1:4*j+4] # skip alpha plane data at nextline[4*j] rv.append(rgb) start = start + rowbytes data = string.join(rv, '') if debug: print "timestamp found", timestamp, "length of image data", len(data) videomedia = videotrack = movie = None # this is required to deallocate memory except Exception, err: writeError(outputImageName, err.__str__())
"""VerySimplePlayer converted to python
"""MovieInWindow converted to python
# Video file reader, using QuickTime