home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / video / Vinfo.py < prev    next >
Text File  |  1996-11-27  |  4KB  |  175 lines

  1. #! /usr/bin/env python
  2.  
  3. # Print some info about a CMIF movie file
  4.  
  5.  
  6. # Usage:
  7. #
  8. # Vinfo [-d] [-q] [-s] [-t] [file] ...
  9.  
  10.  
  11. # Options:
  12. #
  13. # -d       : print deltas between frames instead of frame times
  14. # -q       : quick: don't read the frames
  15. # -s       : don't print times (but do count frames and print the total)
  16. # -t       : terse (one line/file, implies -s)
  17. # file ... : file(s) to inspect; default film.video
  18.  
  19.  
  20. import sys
  21. sys.path.append('/ufs/guido/src/video')
  22. import VFile
  23. import getopt
  24. import string
  25.  
  26.  
  27. # Global options
  28.  
  29. short = 0
  30. quick = 0
  31. delta = 0
  32. terse = 0
  33. maxwidth = 10
  34.  
  35.  
  36. # Main program -- mostly command line parsing
  37.  
  38. def main():
  39.     global short, quick, delta, terse, maxwidth
  40.     try:
  41.         opts, args = getopt.getopt(sys.argv[1:], 'dqst')
  42.     except getopt.error, msg:
  43.         sys.stdout = sys.stderr
  44.         print msg
  45.         print 'usage: Vinfo [-d] [-q] [-s] [-t] [file] ...'
  46.         sys.exit(2)
  47.     for opt, arg in opts:
  48.         if opt == '-q':
  49.             quick = 1
  50.         if opt == '-d':
  51.             delta = 1
  52.         if opt == '-s':
  53.             short = 1
  54.         if opt == '-t':
  55.             terse = short = 1
  56.     if not args:
  57.         args = ['film.video']
  58.     for filename in args:
  59.         maxwidth = max(maxwidth, len(filename))
  60.     sts = 0
  61.     for filename in args:
  62.         if process(filename):
  63.             sts = 1
  64.     sys.exit(sts)
  65.  
  66.  
  67. # Process one file
  68.  
  69. def process(filename):
  70.     try:
  71.         vin = VFile.RandomVinFile(filename)
  72.     except IOError, msg:
  73.         sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
  74.         return 1
  75.     except VFile.Error, msg:
  76.         sys.stderr.write(msg + '\n')
  77.         return 1
  78.     except EOFError:
  79.         sys.stderr.write(filename + ': EOF in video file\n')
  80.         return 1
  81.  
  82.     if terse:
  83.         print string.ljust(filename, maxwidth),
  84.         kbytes = (VFile.getfilesize(filename) + 1023) / 1024
  85.         print string.rjust(`kbytes`, 5) + 'K',
  86.         print ' ', string.ljust(`vin.version`, 5),
  87.         print string.ljust(vin.format, 8),
  88.         print string.rjust(`vin.width`, 4),
  89.         print string.rjust(`vin.height`, 4),
  90.         if type(vin.packfactor) == type(()):
  91.             xpf, ypf = vin.packfactor
  92.             s = string.rjust(`xpf`, 2) + ',' + \
  93.                   string.rjust(`ypf`, 2)
  94.         else:
  95.             s = string.rjust(`vin.packfactor`, 2)
  96.             if type(vin.packfactor) == type(0) and \
  97.                   vin.format not in ('rgb', 'jpeg') and \
  98.                   (vin.width/vin.packfactor) % 4 <> 0:
  99.                 s = s + '!  '
  100.             else:
  101.                 s = s + '   '
  102.         print s,
  103.         sys.stdout.flush()
  104.     else:
  105.         vin.printinfo()
  106.  
  107.     if quick:
  108.         if terse:
  109.             print
  110.         vin.close()
  111.         return 0
  112.  
  113.     try:
  114.         vin.readcache()
  115.         if not terse:
  116.             print '[Using cached index]'
  117.     except VFile.Error:
  118.         if not terse:
  119.             print '[Constructing index on the fly]'
  120.  
  121.     if not short:
  122.         if delta:
  123.             print 'Frame time deltas:',
  124.         else:
  125.             print 'Frame times:',
  126.  
  127.     n = 0
  128.     t = 0
  129.     told = 0
  130.     datasize = 0
  131.     while 1:
  132.         try:
  133.             t, ds, cs = vin.getnextframeheader()
  134.             vin.skipnextframedata(ds, cs)
  135.         except EOFError:
  136.             break
  137.         datasize = datasize + ds
  138.         if cs: datasize = datasize + cs
  139.         if not short:
  140.             if n%8 == 0:
  141.                 sys.stdout.write('\n')
  142.             if delta:
  143.                 sys.stdout.write('\t' + `t - told`)
  144.                 told = t
  145.             else:
  146.                 sys.stdout.write('\t' + `t`)
  147.         n = n+1
  148.  
  149.     if not short: print
  150.  
  151.     if terse:
  152.         print string.rjust(`n`, 6),
  153.         if t: print string.rjust(`int(n*10000.0/t)*0.1`, 5),
  154.         print
  155.     else:
  156.         print 'Total', n, 'frames in', t*0.001, 'sec.',
  157.         if t: print '-- average', int(n*10000.0/t)*0.1, 'frames/sec',
  158.         print
  159.         print 'Total data', 0.1 * int(datasize / 102.4), 'Kbytes',
  160.         if t:
  161.             print '-- average',
  162.             print 0.1 * int(datasize / 0.1024 / t), 'Kbytes/sec',
  163.         print
  164.  
  165.     vin.close()
  166.     return 0
  167.  
  168.  
  169. # Don't forget to call the main program
  170.  
  171. try:
  172.     main()
  173. except KeyboardInterrupt:
  174.     print '[Interrupt]'
  175.