Vinfo.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » Demo » sgi » video » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » Demo » sgi » video » Vinfo.py
#! /usr/bin/env python

# Print some info about a CMIF movie file


# Usage:
#
# Vinfo [-d] [-q] [-s] [-t] [file] ...


# Options:
#
# -d       : print deltas between frames instead of frame times
# -q       : quick: don't read the frames
# -s       : don't print times (but do count frames and print the total)
# -t       : terse (one line/file, implies -s)
# file ... : file(s) to inspect; default film.video


import sys
sys.path.append('/ufs/guido/src/video')
import VFile
import getopt
import string


# Global options

short = 0
quick = 0
delta = 0
terse = 0
maxwidth = 10


# Main program -- mostly command line parsing

def main():
  global short, quick, delta, terse, maxwidth
  try:
    opts, args = getopt.getopt(sys.argv[1:], 'dqst')
  except getopt.error, msg:
    sys.stdout = sys.stderr
    print msg
    print 'usage: Vinfo [-d] [-q] [-s] [-t] [file] ...'
    sys.exit(2)
  for opt, arg in opts:
    if opt == '-q':
      quick = 1
    if opt == '-d':
      delta = 1
    if opt == '-s':
      short = 1
    if opt == '-t':
      terse = short = 1
  if not args:
    args = ['film.video']
  for filename in args:
    maxwidth = max(maxwidth, len(filename))
  sts = 0
  for filename in args:
    if process(filename):
      sts = 1
  sys.exit(sts)


# Process one file

def process(filename):
  try:
    vin = VFile.RandomVinFile(filename)
  except IOError, msg:
    sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
    return 1
  except VFile.Error, msg:
    sys.stderr.write(msg + '\n')
    return 1
  except EOFError:
    sys.stderr.write(filename + ': EOF in video file\n')
    return 1

  if terse:
    print string.ljust(filename, maxwidth),
    kbytes = (VFile.getfilesize(filename) + 1023) / 1024
    print string.rjust(`kbytes`, 5) + 'K',
    print ' ', string.ljust(`vin.version`, 5),
    print string.ljust(vin.format, 8),
    print string.rjust(`vin.width`, 4),
    print string.rjust(`vin.height`, 4),
    if type(vin.packfactor) == type(()):
      xpf, ypf = vin.packfactor
      s = string.rjust(`xpf`, 2) + ',' + \
          string.rjust(`ypf`, 2)
    else:
      s = string.rjust(`vin.packfactor`, 2)
      if type(vin.packfactor) == type(0) and \
          vin.format not in ('rgb', 'jpeg') and \
          (vin.width/vin.packfactor) % 4 <> 0:
        s = s + '!  '
      else:
        s = s + '   '
    print s,
    sys.stdout.flush()
  else:
    vin.printinfo()

  if quick:
    if terse:
      print
    vin.close()
    return 0

  try:
    vin.readcache()
    if not terse:
      print '[Using cached index]'
  except VFile.Error:
    if not terse:
      print '[Constructing index on the fly]'

  if not short:
    if delta:
      print 'Frame time deltas:',
    else:
      print 'Frame times:',

  n = 0
  t = 0
  told = 0
  datasize = 0
  while 1:
    try:
      t, ds, cs = vin.getnextframeheader()
      vin.skipnextframedata(ds, cs)
    except EOFError:
      break
    datasize = datasize + ds
    if cs: datasize = datasize + cs
    if not short:
      if n%8 == 0:
        sys.stdout.write('\n')
      if delta:
        sys.stdout.write('\t' + `t - told`)
        told = t
      else:
        sys.stdout.write('\t' + `t`)
    n = n+1

  if not short: print

  if terse:
    print string.rjust(`n`, 6),
    if t: print string.rjust(`int(n*10000.0/t)*0.1`, 5),
    print
  else:
    print 'Total', n, 'frames in', t*0.001, 'sec.',
    if t: print '-- average', int(n*10000.0/t)*0.1, 'frames/sec',
    print
    print 'Total data', 0.1 * int(datasize / 102.4), 'Kbytes',
    if t:
      print '-- average',
      print 0.1 * int(datasize / 0.1024 / t), 'Kbytes/sec',
    print

  vin.close()
  return 0


# Don't forget to call the main program

try:
  main()
except KeyboardInterrupt:
  print '[Interrupt]'
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.