Commit 59240d65 authored by Jack Jansen's avatar Jack Jansen

- 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.
parent fdb814b6
...@@ -12,11 +12,20 @@ from Carbon import Qd ...@@ -12,11 +12,20 @@ from Carbon import Qd
from Carbon import Qdoffs from Carbon import Qdoffs
from Carbon import QDOffscreen from Carbon import QDOffscreen
from Carbon import Res from Carbon import Res
import MediaDescr try:
import imgformat 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 os
# import audio.format # import audio.format
import macfs
class VideoFormat: class VideoFormat:
def __init__(self, name, descr, width, height, format): def __init__(self, name, descr, width, height, format):
...@@ -40,8 +49,7 @@ class VideoFormat: ...@@ -40,8 +49,7 @@ class VideoFormat:
class _Reader: class _Reader:
def __init__(self, path): def __init__(self, path):
fsspec = macfs.FSSpec(path) fd = Qt.OpenMovieFile(path, 0)
fd = Qt.OpenMovieFile(fsspec, 0)
self.movie, d1, d2 = Qt.NewMovieFromFile(fd, 0, 0) self.movie, d1, d2 = Qt.NewMovieFromFile(fd, 0, 0)
self.movietimescale = self.movie.GetMovieTimeScale() self.movietimescale = self.movie.GetMovieTimeScale()
try: try:
...@@ -55,7 +63,7 @@ class _Reader: ...@@ -55,7 +63,7 @@ class _Reader:
handle = Res.Handle('') handle = Res.Handle('')
n = self.audiomedia.GetMediaSampleDescriptionCount() n = self.audiomedia.GetMediaSampleDescriptionCount()
self.audiomedia.GetMediaSampleDescription(1, handle) self.audiomedia.GetMediaSampleDescription(1, handle)
self.audiodescr = MediaDescr.SoundDescription.decode(handle.data) self.audiodescr = _audiodescr(handle.data)
self.audiotimescale = self.audiomedia.GetMediaTimeScale() self.audiotimescale = self.audiomedia.GetMediaTimeScale()
del handle del handle
...@@ -139,6 +147,8 @@ class _Reader: ...@@ -139,6 +147,8 @@ class _Reader:
return self._gettrackduration_ms(self.videotrack) return self._gettrackduration_ms(self.videotrack)
def GetAudioFormat(self): def GetAudioFormat(self):
if not self.audiodescr:
return None, None, None, None, None
bps = self.audiodescr['sampleSize'] bps = self.audiodescr['sampleSize']
nch = self.audiodescr['numChannels'] nch = self.audiodescr['numChannels']
if nch == 1: if nch == 1:
...@@ -167,12 +177,14 @@ class _Reader: ...@@ -167,12 +177,14 @@ class _Reader:
return channels, encoding, blocksize, fpb, bps return channels, encoding, blocksize, fpb, bps
def GetAudioFrameRate(self): def GetAudioFrameRate(self):
if not self.audiodescr:
return None
return int(self.audiodescr['sampleRate']) return int(self.audiodescr['sampleRate'])
def GetVideoFormat(self): def GetVideoFormat(self):
width = self.videodescr['width'] width = self.videodescr['width']
height = self.videodescr['height'] height = self.videodescr['height']
return VideoFormat('dummy_format', 'Dummy Video Format', width, height, imgformat.macrgb) return VideoFormat('dummy_format', 'Dummy Video Format', width, height, macrgb)
def GetVideoFrameRate(self): def GetVideoFrameRate(self):
tv = self.videocurtime tv = self.videocurtime
...@@ -236,18 +248,20 @@ def reader(url): ...@@ -236,18 +248,20 @@ def reader(url):
return rdr return rdr
def _test(): def _test():
import img import EasyDialogs
try:
import img
except ImportError:
img = None
import MacOS import MacOS
Qt.EnterMovies() Qt.EnterMovies()
fss, ok = macfs.PromptGetFile('Video to convert') path = EasyDialogs.AskFileForOpen(message='Video to convert')
if not ok: sys.exit(0) if not path: sys.exit(0)
path = fss.as_pathname()
rdr = reader(path) rdr = reader(path)
if not rdr: if not rdr:
sys.exit(1) sys.exit(1)
dstfss, ok = macfs.StandardPutFile('Name for output folder') dstdir = EasyDialogs.AskFileForSave(message='Name for output folder')
if not ok: sys.exit(0) if not dstdir: sys.exit(0)
dstdir = dstfss.as_pathname()
num = 0 num = 0
os.mkdir(dstdir) os.mkdir(dstdir)
videofmt = rdr.GetVideoFormat() videofmt = rdr.GetVideoFormat()
...@@ -258,16 +272,18 @@ def _test(): ...@@ -258,16 +272,18 @@ def _test():
fname = 'frame%04.4d.jpg'%num fname = 'frame%04.4d.jpg'%num
num = num+1 num = num+1
pname = os.path.join(dstdir, fname) pname = os.path.join(dstdir, fname)
print 'Writing', fname, imgw, imgh, len(data) if not img: print 'Not',
wrt = img.writer(imgfmt, pname) print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
wrt.width = imgw if img:
wrt.height = imgh wrt = img.writer(imgfmt, pname)
wrt.write(data) wrt.width = imgw
timestamp, data = rdr.ReadVideo() wrt.height = imgh
MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG') wrt.write(data)
if num > 20: timestamp, data = rdr.ReadVideo()
print 'stopping at 20 frames so your disk does not fill up:-)' MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG')
break if num > 20:
print 'stopping at 20 frames so your disk does not fill up:-)'
break
print 'Total frames:', num print 'Total frames:', num
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment