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

# Compress an rgb or grey video file to jpeg format


# Usage:
#
# Vmkjpeg [infile [outfile]]


# Options:
#
# infile     : input file (default film.video)
# outfile    : output file (default out.video)


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


# Main program -- mostly command line parsing

def main():
  args = sys.argv[1:]
  if len(args) < 1:
    args.append('film.video')
  if len(args) < 2:
    args.append('out.video')
  if len(args) > 2:
    sys.stderr.write('usage: Vmkjpeg [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

  info = vin.getinfo()
  if info[0] == 'rgb':
    width, height = vin.getsize()
    bytes = 4
    format = 'jpeg'
  elif info[0] == 'grey':
    width, height = vin.getsize()
    pf = vin.packfactor
    width, height = width / pf, height / pf
    bytes = 1
    format = 'jpeggrey'
  else:
    sys.stderr.write('Vmkjpeg: input not in rgb or grey format\n')
    return 1
  info = (format,) + info[1:]
  vout.setinfo(info)
  vout.writeheader()
  n = 0
  try:
    while 1:
      t, data, cdata = vin.getnextframe()
      n = n + 1
      sys.stderr.write('Frame ' + `n` + '...')
      data = jpeg.compress(data, width, height, bytes)
      vout.writeframe(t, data, None)
      sys.stderr.write('\n')
  except EOFError:
    pass
  return 0


# 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.