Example #1
0
File: Vb.py Project: carol8421/gosh
	def cont_capture(self):
		saved_label = self.b_capture.label
		self.b_capture.label = 'Stop\n' + saved_label
		self.open_if_closed()
		self.init_cont()
		fps = 59.64		# Fields per second
		# XXX (fps of Indigo monitor, not of PAL or NTSC!)
		tpf = 1000.0 / fps	# Time per field in msec
		self.capturing = 1
		self.start_audio()
		while 1:
			try:
				void = fl.check_forms()
			except StopCapture:
				break
			try:
				cd, id = self.video.GetCaptureData()
			except sv.error:
				sgi.nap(1)
				continue
			id = id + 2*self.rate
			data = cd.InterleaveFields(1)
			cd.UnlockCaptureData()
			t = id*tpf
			if not self.write_frame(t, data):
				break
		self.stop_audio()
		self.capturing = 0
		self.end_cont()
		if self.aout:
			# If recording audio, can't capture multiple sequences
			self.reset()
		self.b_capture.label = saved_label
Example #2
0
	def cont_capture(self):
		saved_label = self.b_capture.label
		self.b_capture.label = 'Stop\n' + saved_label
		self.open_if_closed()
		self.init_cont()
		fps = 59.64		# Fields per second
		# XXX (fps of Indigo monitor, not of PAL or NTSC!)
		tpf = 1000.0 / fps	# Time per field in msec
		self.capturing = 1
		self.start_audio()
		while 1:
			try:
				void = fl.check_forms()
			except StopCapture:
				break
			try:
				cd, id = self.video.GetCaptureData()
			except sv.error:
				sgi.nap(1)
				continue
			id = id + 2*self.rate
			data = cd.InterleaveFields(1)
			cd.UnlockCaptureData()
			t = id*tpf
			if not self.write_frame(t, data):
				break
		self.stop_audio()
		self.capturing = 0
		self.end_cont()
		if self.aout:
			# If recording audio, can't capture multiple sequences
			self.reset()
		self.b_capture.label = saved_label
Example #3
0
File: Vb.py Project: carol8421/gosh
	def single_capture(self, stepfunc, timecode):
		self.open_if_closed()
		self.init_cont()
		while 1:
			try:
				cd, id = self.video.GetCaptureData()
				break
			except sv.error:
				pass
			sgi.nap(1)
			if stepfunc:		# This might step the video
				d=stepfunc()	# to the next frame
		if not self.use_24:
			data = cd.InterleaveFields(1)
		else:
			x, y = self.vout.getsize()
			if self.use_compress:
				if self.rgb24_size == 1:
					data = cd.YUVtoYUV422DC(0)
				elif self.rgb24_size == 2:
					data = cd.YUVtoYUV422DC_quarter(1)
					x = x/2
					y = y/2
				elif self.rgb24_size == 3:
					data = cd.YUVtoYUV422DC_sixteenth(1)
					x = x/4
					y = y/4
			else:
				data = cd.YUVtoRGB(1)
				if self.maxx*self.maxy*4 <> len(data):
					print 'maxx,maxy,exp,got=', self.maxx,
					print self.maxy,self.maxx*self.maxy*4,
					print len(data)
					fl.showmessage('Wrong sized data')
					return 0
				if self.rgb24_size <> 1:
					data = imageop.scale(data, 4, \
						  self.maxx, self.maxy, x, y)
			if self.use_jpeg:
				import jpeg
				data = jpeg.compress(data, x, y, 4)
			if self.use_compress:
				data = self.compressor.Compress(1, data)
		cd.UnlockCaptureData()
		self.end_cont()
		if timecode == None:
			timecode = (self.nframes+1) * (1000/25)
		return self.write_frame(timecode, data)
Example #4
0
	def single_capture(self, stepfunc, timecode):
		self.open_if_closed()
		self.init_cont()
		while 1:
			try:
				cd, id = self.video.GetCaptureData()
				break
			except sv.error:
				pass
			sgi.nap(1)
			if stepfunc:		# This might step the video
				d=stepfunc()	# to the next frame
		if not self.use_24:
			data = cd.InterleaveFields(1)
		else:
			x, y = self.vout.getsize()
			if self.use_compress:
				if self.rgb24_size == 1:
					data = cd.YUVtoYUV422DC(0)
				elif self.rgb24_size == 2:
					data = cd.YUVtoYUV422DC_quarter(1)
					x = x/2
					y = y/2
				elif self.rgb24_size == 3:
					data = cd.YUVtoYUV422DC_sixteenth(1)
					x = x/4
					y = y/4
			else:
				data = cd.YUVtoRGB(1)
				if self.maxx*self.maxy*4 <> len(data):
					print 'maxx,maxy,exp,got=', self.maxx,
					print self.maxy,self.maxx*self.maxy*4,
					print len(data)
					fl.showmessage('Wrong sized data')
					return 0
				if self.rgb24_size <> 1:
					data = imageop.scale(data, 4, \
						  self.maxx, self.maxy, x, y)
			if self.use_jpeg:
				import jpeg
				data = jpeg.compress(data, x, y, 4)
			if self.use_compress:
				data = self.compressor.Compress(1, data)
		cd.UnlockCaptureData()
		self.end_cont()
		if timecode == None:
			timecode = (self.nframes+1) * (1000/25)
		return self.write_frame(timecode, data)
Example #5
0
#! /usr/bin/env python
Example #6
0
def record(v, info, filename, audiofilename, mono, grey, greybits, \
	  monotreshold, fields, preallocspace):
	import thread
	format, x, y, qsize, rate = info
	fps = 59.64 # Fields per second
	# XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
	tpf = 1000.0 / fps # Time per field in msec
	if filename:
		vout = VFile.VoutFile(filename)
		if mono:
			format = 'mono'
		elif grey and greybits == 8:
			format = 'grey'
		elif grey:
			format = 'grey'+`abs(greybits)`
		else:
			format = 'rgb8'
		vout.setformat(format)
		vout.setsize(x, y)
		if fields:
			vout.setpf((1, -2))
		vout.writeheader()
		if preallocspace:
			print 'Preallocating space...'
			vout.prealloc(preallocspace)
			print 'done.'
		MAXSIZE = 20 # XXX should be a user option
		import Queue
		queue = Queue.Queue(MAXSIZE)
		done = thread.allocate_lock()
		done.acquire_lock()
		convertor = None
		if grey:
			if greybits == 2:
				convertor = imageop.grey2grey2
			elif greybits == 4:
				convertor = imageop.grey2grey4
			elif greybits == -2:
				convertor = imageop.dither2grey2
		thread.start_new_thread(saveframes, \
			  (vout, queue, done, mono, monotreshold, convertor))
		if audiofilename:
			audiodone = thread.allocate_lock()
			audiodone.acquire_lock()
			audiostop = []
			initaudio(audiofilename, audiostop, audiodone)
	gl.wintitle('(rec) ' + filename)
	lastid = 0
	t0 = time.time()
	count = 0
	ids = []
	v.InitContinuousCapture(info)
	while not gl.qtest():
		try:
			cd, id = v.GetCaptureData()
		except sv.error:
			#time.sleep(0.010) # XXX is this necessary?
			sgi.nap(1)	# XXX Try by Jack
			continue
		ids.append(id)
		
		id = id + 2*rate
##		if id <> lastid + 2*rate:
##			print lastid, id
		lastid = id
		count = count+1
		if fields:
			data1, data2 = cd.GetFields()
			cd.UnlockCaptureData()
			if filename:
				queue.put((data1, int(id*tpf)))
				queue.put((data2, int((id+1)*tpf)))
		else:
			data = cd.InterleaveFields(1)
			cd.UnlockCaptureData()
			if filename:
				queue.put((data, int(id*tpf)))
	t1 = time.time()
	gl.wintitle('(busy) ' + filename)
	print lastid, 'fields in', round(t1-t0, 3), 'sec',
	print '--', round(lastid/(t1-t0), 1), 'fields/sec'
	print 'Captured',count*2, 'fields,',
	print round(count*2/(t1-t0), 1), 'f/s',
	if lastid:
		print '(',
		print round(count*200.0/lastid), '%, or',
		print round(count*rate*200.0/lastid), '% of wanted rate )',
	print
	if ids:
		print 'Ids:',
		t0 = ids[0]
		del ids[0]
		for t1 in ids:
			print t1-t0,
			t0 = t1
		print
	if filename and audiofilename:
		audiostop.append(None)
		audiodone.acquire_lock()
	v.EndContinuousCapture()
	if filename:
		queue.put(None) # Sentinel
		done.acquire_lock()
	gl.wintitle('(done) ' + filename)
Example #7
0
def record(v, info, filename, audiofilename, mono, grey, greybits, \
   monotreshold, fields, preallocspace):
    import thread
    format, x, y, qsize, rate = info
    fps = 59.64  # Fields per second
    # XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
    tpf = 1000.0 / fps  # Time per field in msec
    if filename:
        vout = VFile.VoutFile(filename)
        if mono:
            format = 'mono'
        elif grey and greybits == 8:
            format = 'grey'
        elif grey:
            format = 'grey' + ` abs(greybits) `
        else:
            format = 'rgb8'
        vout.setformat(format)
        vout.setsize(x, y)
        if fields:
            vout.setpf((1, -2))
        vout.writeheader()
        if preallocspace:
            print 'Preallocating space...'
            vout.prealloc(preallocspace)
            print 'done.'
        MAXSIZE = 20  # XXX should be a user option
        import Queue
        queue = Queue.Queue(MAXSIZE)
        done = thread.allocate_lock()
        done.acquire_lock()
        convertor = None
        if grey:
            if greybits == 2:
                convertor = imageop.grey2grey2
            elif greybits == 4:
                convertor = imageop.grey2grey4
            elif greybits == -2:
                convertor = imageop.dither2grey2
        thread.start_new_thread(saveframes, \
           (vout, queue, done, mono, monotreshold, convertor))
        if audiofilename:
            audiodone = thread.allocate_lock()
            audiodone.acquire_lock()
            audiostop = []
            initaudio(audiofilename, audiostop, audiodone)
    gl.wintitle('(rec) ' + filename)
    lastid = 0
    t0 = time.time()
    count = 0
    ids = []
    v.InitContinuousCapture(info)
    while not gl.qtest():
        try:
            cd, id = v.GetCaptureData()
        except sv.error:
            #time.sleep(0.010) # XXX is this necessary?
            sgi.nap(1)  # XXX Try by Jack
            continue
        ids.append(id)

        id = id + 2 * rate
        ##		if id <> lastid + 2*rate:
        ##			print lastid, id
        lastid = id
        count = count + 1
        if fields:
            data1, data2 = cd.GetFields()
            cd.UnlockCaptureData()
            if filename:
                queue.put((data1, int(id * tpf)))
                queue.put((data2, int((id + 1) * tpf)))
        else:
            data = cd.InterleaveFields(1)
            cd.UnlockCaptureData()
            if filename:
                queue.put((data, int(id * tpf)))
    t1 = time.time()
    gl.wintitle('(busy) ' + filename)
    print lastid, 'fields in', round(t1 - t0, 3), 'sec',
    print '--', round(lastid / (t1 - t0), 1), 'fields/sec'
    print 'Captured', count * 2, 'fields,',
    print round(count * 2 / (t1 - t0), 1), 'f/s',
    if lastid:
        print '(',
        print round(count * 200.0 / lastid), '%, or',
        print round(count * rate * 200.0 / lastid), '% of wanted rate )',
    print
    if ids:
        print 'Ids:',
        t0 = ids[0]
        del ids[0]
        for t1 in ids:
            print t1 - t0,
            t0 = t1
        print
    if filename and audiofilename:
        audiostop.append(None)
        audiodone.acquire_lock()
    v.EndContinuousCapture()
    if filename:
        queue.put(None)  # Sentinel
        done.acquire_lock()
    gl.wintitle('(done) ' + filename)
Example #8
0
#! /usr/bin/env python
Example #9
0
#! /usr/bin/env python