blob: 651deee00d3b66e6745863adb01df38ca2443f6c [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossum99e237f1992-08-20 11:53:14 +00002
3# Manipulate the time base of CMIF movies
4
5
6# Possibilities:
7#
8# - resample at a fixed rate
9# - divide the time codes by a speed factor (to make it go faster/slower)
Jeremy Hyltona05e2932000-06-28 14:48:01 +000010# - drop frames that are less than n msec apart (to accommodate slow players)
Guido van Rossum99e237f1992-08-20 11:53:14 +000011
12
13# Usage:
14#
15# Vtime [-m msec] [-r msec] [-s speed] [infile [outfile]]
16
17
18# Options:
19#
20# -m n : drop frames closer than n msec (default 0)
21# -r n : regenerate input time base n msec apart
22# -s speed : speed change factor after other processing (default 1.0)
23# infile : input file (default film.video)
24# outfile : output file (default out.video)
25
26
27import sys
28sys.path.append('/ufs/guido/src/video')
29import VFile
30import getopt
31import string
32
33
34# Global options
35
36speed = 1.0
37mindelta = 0
38regen = None
39
40
41# Main program -- mostly command line parsing
42
43def main():
44 global speed, mindelta
45 opts, args = getopt.getopt(sys.argv[1:], 'm:r:s:')
46 for opt, arg in opts:
47 if opt == '-m':
48 mindelta = string.atoi(arg)
49 elif opt == '-r':
50 regen = string.atoi(arg)
51 elif opt == '-s':
52 speed = float(eval(arg))
53 if len(args) < 1:
54 args.append('film.video')
55 if len(args) < 2:
56 args.append('out.video')
57 if len(args) > 2:
58 sys.stderr.write('usage: Vtime [options] [infile [outfile]]\n')
59 sys.exit(2)
60 sts = process(args[0], args[1])
61 sys.exit(sts)
62
63
64# Copy one file to another
65
66def process(infilename, outfilename):
67 try:
Guido van Rossum21a3ff91993-12-17 15:11:41 +000068 vin = VFile.BasicVinFile(infilename)
Guido van Rossum99e237f1992-08-20 11:53:14 +000069 except IOError, msg:
70 sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
71 return 1
72 except VFile.Error, msg:
73 sys.stderr.write(msg + '\n')
74 return 1
75 except EOFError:
76 sys.stderr.write(infilename + ': EOF in video file\n')
77 return 1
78
79 try:
Guido van Rossum21a3ff91993-12-17 15:11:41 +000080 vout = VFile.BasicVoutFile(outfilename)
Guido van Rossum99e237f1992-08-20 11:53:14 +000081 except IOError, msg:
82 sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
83 return 1
84
85 vout.setinfo(vin.getinfo())
86 vout.writeheader()
87
88 told = 0
89 nin = 0
90 nout = 0
91 tin = 0
92 tout = 0
93
94 while 1:
95 try:
96 tin, data, cdata = vin.getnextframe()
97 except EOFError:
98 break
99 nin = nin + 1
100 if regen:
101 tout = nin * regen
102 else:
103 tout = tin
104 tout = int(tout / speed)
105 if tout - told < mindelta:
106 continue
107 told = tout
108 vout.writeframe(tout, data, cdata)
109 nout = nout + 1
110
111 vout.close()
112 vin.close()
113
114
115# Don't forget to call the main program
116
117main()