cpython/Demo/sgi/video/Vplay.py

135 lines
2.7 KiB
Python
Raw Normal View History

1992-08-18 14:01:02 -03:00
#! /usr/local/python
# Play CMIF movie files
# Usage:
#
# Vplay [-l] [-m maginfy] [file] ...
# Options:
#
# -l : loop, playing the movie over and over again
# -m magnify : magnify the image by the given factor
# file ... : file(s) to play; default film.video
# User interface:
#
# Place the windo where you want it. The size is determined by the
# movie file and the -m option.
#
# Press ESC or select the window manager Quit or Close window option
# to close a window; if more files are given the window for the next
# file now pops up.
1992-08-18 11:16:12 -03:00
import sys
1992-08-18 14:01:02 -03:00
sys.path.append('/ufs/guido/src/video')
1992-08-18 11:16:12 -03:00
import VFile
import time
import gl, GL
from DEVICE import *
1992-08-18 14:01:02 -03:00
import getopt
import string
# Global options
magnify = 1
looping = 0
# Main program -- mostly command line parsing
1992-08-18 11:16:12 -03:00
def main():
1992-08-18 14:01:02 -03:00
global magnify, looping
opts, args = getopt.getopt(sys.argv[1:], 'lm:')
for opt, arg in opts:
if opt == '-l':
looping = 1
elif opt == '-m':
magnify = string.atoi(arg)
if not args:
args = ['film.video']
for filename in args:
process(filename)
# Process one file
1992-08-18 11:16:12 -03:00
def process(filename):
vin = VFile.VinFile().init(filename)
print 'File: ', filename
print 'Version: ', vin.version
print 'Size: ', vin.width, 'x', vin.height
print 'Pack: ', vin.packfactor, '; chrom:', vin.chrompack
print 'Bits: ', vin.c0bits, vin.c1bits, vin.c2bits
print 'Format: ', vin.format
print 'Offset: ', vin.offset
1992-08-18 14:01:02 -03:00
vin.magnify = magnify
1992-08-18 11:16:12 -03:00
gl.foreground()
1992-08-18 14:01:02 -03:00
gl.prefsize(vin.width * magnify, vin.height * magnify)
win = gl.winopen('* ' + filename)
1992-08-18 11:16:12 -03:00
vin.initcolormap()
gl.qdevice(ESCKEY)
gl.qdevice(WINSHUT)
gl.qdevice(WINQUIT)
t0 = time.millitimer()
running = 1
data = None
1992-08-18 14:01:02 -03:00
t = 0
n = 0
1992-08-18 11:16:12 -03:00
while 1:
if running:
try:
t, data, chromdata = vin.getnextframe()
1992-08-18 14:01:02 -03:00
n = n+1
1992-08-18 11:16:12 -03:00
except EOFError:
1992-08-18 14:01:02 -03:00
t1 = time.millitimer()
gl.wintitle(filename)
1992-08-18 14:01:02 -03:00
print 'Recorded:', n,
print 'frames in', t*0.001, 'sec.',
if t:
print '-- average',
print int(n*10000.0/t)*0.1,
print 'frames/sec',
print
t = t1-t0
print 'Played:', n,
print 'frames in', t*0.001, 'sec.',
if t:
print '-- average',
print int(n*10000.0/t)*0.1,
print 'frames/sec',
print
if looping and n > 0:
vin.rewind()
vin.magnify = magnify
continue
else:
running = 0
1992-08-18 11:16:12 -03:00
if running:
dt = t + t0 - time.millitimer()
if dt > 0:
time.millisleep(dt)
1992-08-18 14:01:02 -03:00
vin.showframe(data, chromdata)
1992-08-18 11:16:12 -03:00
if not running or gl.qtest():
dev, val = gl.qread()
if dev in (ESCKEY, WINSHUT, WINQUIT):
1992-08-18 14:01:02 -03:00
gl.winclose(win)
1992-08-18 11:16:12 -03:00
break
if dev == REDRAW:
gl.reshapeviewport()
if data:
vin.showframe(data, chromdata)
1992-08-18 14:01:02 -03:00
# Don't forget to call the main program
1992-08-18 11:16:12 -03:00
main()