Vtime.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 » Vtime.py
#! /usr/bin/env python

# Manipulate the time base of CMIF movies


# Possibilities:
#
# - resample at a fixed rate
# - divide the time codes by a speed factor (to make it go faster/slower)
# - drop frames that are less than n msec apart (to accomodate slow players)


# Usage:
#
# Vtime [-m msec] [-r msec] [-s speed] [infile [outfile]]


# Options:
#
# -m n       : drop frames closer than n msec (default 0)
# -r n       : regenerate input time base n msec apart
# -s speed   : speed change factor after other processing (default 1.0)
# infile     : input file (default film.video)
# outfile    : output file (default out.video)


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


# Global options

speed = 1.0
mindelta = 0
regen = None


# Main program -- mostly command line parsing

def main():
  global speed, mindelta
  opts, args = getopt.getopt(sys.argv[1:], 'm:r:s:')
  for opt, arg in opts:
    if opt == '-m':
      mindelta = string.atoi(arg)
    elif opt == '-r':
      regen = string.atoi(arg)
    elif opt == '-s':
      speed = float(eval(arg))
  if len(args) < 1:
    args.append('film.video')
  if len(args) < 2:
    args.append('out.video')
  if len(args) > 2:
    sys.stderr.write('usage: Vtime [options] [infile [outfile]]\n')
    sys.exit(2)
  sts = process(args[0], args[1])
  sys.exit(sts)


# Copy one file to another

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

  try:
    vout = VFile.BasicVoutFile(outfilename)
  except IOError, msg:
    sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
    return 1

  vout.setinfo(vin.getinfo())
  vout.writeheader()
  
  told = 0
  nin = 0
  nout = 0
  tin = 0
  tout = 0

  while 1:
    try:
      tin, data, cdata = vin.getnextframe()
    except EOFError:
      break
    nin = nin + 1
    if regen:
      tout = nin * regen
    else:
      tout = tin
    tout = int(tout / speed)
    if tout - told < mindelta:
      continue
    told = tout
    vout.writeframe(tout, data, cdata)
    nout = nout + 1

  vout.close()
  vin.close()


# Don't forget to call the main program

main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.