[Python-checkins] python/dist/src/Lib/plat-mac videoreader.py,1.1,1.2

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Tue, 04 Feb 2003 07:36:46 -0800


Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1:/tmp/cvs-serv7687

Modified Files:
	videoreader.py 
Log Message:
- Handle the img and MediaFormat modules not being available (by not
providing the format info, only the raw data).
- Get rid of fsspecs.
- Make the demo program at least do something if img not available.


Index: videoreader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/videoreader.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** videoreader.py	30 Dec 2002 22:04:20 -0000	1.1
--- videoreader.py	4 Feb 2003 15:36:42 -0000	1.2
***************
*** 13,21 ****
  from Carbon import QDOffscreen
  from Carbon import Res
! import MediaDescr
! import imgformat
  import os
  # import audio.format
- import macfs
  
  class VideoFormat:
--- 13,30 ----
  from Carbon import QDOffscreen
  from Carbon import Res
! try:
! 	import MediaDescr
! except ImportError:
! 	def _audiodescr(data):
! 		return None
! else:
! 	def _audiodescr(data):
! 		return MediaDescr.SoundDescription.decode(data)
! try:
! 	from imgformat import macrgb
! except ImportError:
! 	macrgb = "Macintosh RGB format"
  import os
  # import audio.format
  
  class VideoFormat:
***************
*** 41,46 ****
  class _Reader:
  	def __init__(self, path):
! 		fsspec = macfs.FSSpec(path)
! 		fd = Qt.OpenMovieFile(fsspec, 0)
  		self.movie, d1, d2 = Qt.NewMovieFromFile(fd, 0, 0)
  		self.movietimescale = self.movie.GetMovieTimeScale()
--- 50,54 ----
  class _Reader:
  	def __init__(self, path):
! 		fd = Qt.OpenMovieFile(path, 0)
  		self.movie, d1, d2 = Qt.NewMovieFromFile(fd, 0, 0)
  		self.movietimescale = self.movie.GetMovieTimeScale()
***************
*** 56,60 ****
  			n = self.audiomedia.GetMediaSampleDescriptionCount()
  			self.audiomedia.GetMediaSampleDescription(1, handle)
! 			self.audiodescr = MediaDescr.SoundDescription.decode(handle.data)
  			self.audiotimescale = self.audiomedia.GetMediaTimeScale()
  			del handle
--- 64,68 ----
  			n = self.audiomedia.GetMediaSampleDescriptionCount()
  			self.audiomedia.GetMediaSampleDescription(1, handle)
! 			self.audiodescr = _audiodescr(handle.data)
  			self.audiotimescale = self.audiomedia.GetMediaTimeScale()
  			del handle
***************
*** 140,143 ****
--- 148,153 ----
  		
  	def GetAudioFormat(self):
+ 		if not self.audiodescr:
+ 			return None, None, None, None, None
  		bps = self.audiodescr['sampleSize']
  		nch = self.audiodescr['numChannels']
***************
*** 168,171 ****
--- 178,183 ----
  			
  	def GetAudioFrameRate(self):
+ 		if not self.audiodescr:
+ 			return None
  		return int(self.audiodescr['sampleRate'])
  		
***************
*** 173,177 ****
  		width = self.videodescr['width']
  		height = self.videodescr['height']
! 		return VideoFormat('dummy_format', 'Dummy Video Format', width, height, imgformat.macrgb)
  		
  	def GetVideoFrameRate(self):
--- 185,189 ----
  		width = self.videodescr['width']
  		height = self.videodescr['height']
! 		return VideoFormat('dummy_format', 'Dummy Video Format', width, height, macrgb)
  		
  	def GetVideoFrameRate(self):
***************
*** 237,252 ****
  
  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()
  	rdr = reader(path)
  	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)
--- 249,266 ----
  
  def _test():
! 	import EasyDialogs
! 	try:
! 		import img
! 	except ImportError:
! 		img = 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)
***************
*** 259,272 ****
  		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: 
! 			print 'stopping at 20 frames so your disk does not fill up:-)'
! 			break
  	print 'Total frames:', num
  		
--- 273,288 ----
  		num = num+1
  		pname = os.path.join(dstdir, fname)
! 		if not img: print 'Not',
! 		print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
! 		if img:
! 			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: 
! 				print 'stopping at 20 frames so your disk does not fill up:-)'
! 				break
  	print 'Total frames:', num