~ubuntu-branches/ubuntu/karmic/tovid/karmic

« back to all changes in this revision

Viewing changes to src/genvid

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2008-01-24 22:04:40 UTC
  • Revision ID: james.westby@ubuntu.com-20080124220440-x7cheljduf1rdgnq
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# genvid
 
3
 
 
4
import os
 
5
import sys
 
6
from libtovid.opts import Option, OptionDict
 
7
from libtovid.flipbook import Flipbook
 
8
from libtovid.effect import Movement, Fade, Colorfade, Spectrum, Scale
 
9
from libtovid import layer
 
10
 
 
11
# Valid command-line options to this script
 
12
cli_opts = [\
 
13
    Option('out', 'FILE', None,
 
14
           """Use the given output file prefix (.m2v added automatically)"""),
 
15
    Option('format', '[vcd|svcd|dvd]', 'dvd',
 
16
           """Output in the given video disc format."""),
 
17
    Option('tvsys', '[pal|ntsc]', 'ntsc',
 
18
           """Output for given TV system."""),
 
19
    Option('seconds', 'NUM', 10,
 
20
           """Number of seconds of output video"""),
 
21
    Option('bgcolor', 'COLOR', 'black',
 
22
           """Use the given background color"""),
 
23
    Option('title', 'TEXT', '',
 
24
           """Display the given title text"""),
 
25
    Option('thumbs', 'FILE[,FILE...]', [],
 
26
           """Create thumbnail images of the given list of images"""),
 
27
    Option('test', '[safe|fonts]', 'all',
 
28
           """Render a screen-test video, for gauging the safe area or font
 
29
           capabilities of your TV or monitor.""")
 
30
    ]
 
31
 
 
32
# TODO: Write a backend to allow genvid to create a video sequence displaying
 
33
# statistics about a video or videos (via 'idvid'), and for rendering something
 
34
# equivalent to an "about this disc" still-image, i.e.
 
35
#     "This disc was generated on 2006-07-04, by tovid version 0.27"
 
36
# along with, i.e.
 
37
#     101 - The Tick vs. The Idea Men.mpg
 
38
#         303MB, 720x480, 9000kbps, 00h:20m:54s
 
39
#     102 - The Tick vs. Chairface Chippendale.mpg
 
40
#         234MB, 720x480, 9000kbps, 00h:19m:16s
 
41
#     ...
 
42
 
 
43
# Main function
 
44
if __name__ == '__main__':
 
45
    # Fill useropts with default values
 
46
    useropts = OptionDict(cli_opts)
 
47
 
 
48
    # Print usage notes if not enough arguments were given
 
49
    if len(sys.argv) < 3:
 
50
        print "Usage: genvid [OPTIONS] -out FILE"
 
51
        print "where OPTIONS may be:"
 
52
        print useropts.usage()
 
53
        sys.exit(1)
 
54
    # Override with any options provided on the command-line
 
55
    else:
 
56
        useropts.override(sys.argv[1:])
 
57
 
 
58
    # Make sure output prefix was provided
 
59
    if not useropts['out']:
 
60
        print "Please provide an output prefix with -out"
 
61
        sys.exit(1)
 
62
 
 
63
    # TODO: VCD/SVCD support
 
64
    if useropts['tvsys'].lower() == 'pal':
 
65
        flip = Flipbook(useropts['seconds'], (720, 576))
 
66
    elif useropts['tvsys'].lower() == 'ntsc':
 
67
        flip = Flipbook(useropts['seconds'], (720, 480))
 
68
    else:
 
69
        print "-tvsys must be 'pal' or 'ntsc'"
 
70
        sys.exit(1)
 
71
        
 
72
    # Background color
 
73
    bgd = layer.Background(color=useropts['bgcolor'])
 
74
    flip.add(bgd)
 
75
 
 
76
    # Title string
 
77
    if useropts['title'] is not '':
 
78
        # TODO: Centered text! (gravity)
 
79
        title = layer.Text(useropts['title'], fontsize=30)
 
80
        flip.add(title, (240, 420))
 
81
    # Thumbnails
 
82
    if useropts['thumbs'] != []:
 
83
        thumbs = layer.ThumbGrid(useropts['thumbs'], (600, 400))
 
84
        flip.add(thumbs, (60, 40))
 
85
 
 
86
 
 
87
    # Test safe area or fonts
 
88
    if 'safe' in useropts['test']:
 
89
        flip.add(layer.SafeArea(90, 'red'))
 
90
        flip.add(layer.SafeArea(80, 'blue'))
 
91
        flip.add(layer.SafeArea(70, 'green'))
 
92
        flip.add(layer.SafeArea(60, 'yellow'))
 
93
    if 'fonts' in useropts['test']:
 
94
        pass
 
95
    
 
96
    # Render the .m2v video
 
97
    flip.render_video(useropts['out'], useropts['format'], useropts['tvsys'])