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

« back to all changes in this revision

Viewing changes to src/tovid-test

  • 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 bash
 
2
ME="[tovid-test]:"
 
3
. tovid-init
 
4
 
 
5
# tovid-test
 
6
# Part of the tovid suite
 
7
# =======================
 
8
# A bash script for testing the tovid suite.
 
9
#
 
10
# Project homepage: http://www.tovid.org
 
11
#
 
12
#
 
13
# Copyright (C) 2005 tovid.org <http://www.tovid.org>
 
14
#
 
15
# This program is free software; you can redistribute it and/or
 
16
# modify it under the terms of the GNU General Public License
 
17
# as published by the Free Software Foundation; either
 
18
# version 2 of the License, or (at your option) any later
 
19
# version.
 
20
#
 
21
# This program is distributed in the hope that it will be useful,
 
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
# GNU General Public License for more details.
 
25
#
 
26
# You should have received a copy of the GNU General Public License
 
27
# along with this program; if not, write to the Free Software
 
28
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Or see:
 
29
#
 
30
#           http://www.gnu.org/licenses/gpl.txt
 
31
 
 
32
# ******************************************************************************
 
33
# ******************************************************************************
 
34
#
 
35
#
 
36
# DEFAULTS AND GLOBALS
 
37
#
 
38
#
 
39
# ******************************************************************************
 
40
# ******************************************************************************
 
41
 
 
42
SEPARATOR="========================================================="
 
43
 
 
44
SCRIPT_NAME=`cat << EOF
 
45
--------------------------------
 
46
tovid-test
 
47
Part of the tovid suite, version $TOVID_VERSION
 
48
$TOVID_HOME_PAGE
 
49
--------------------------------
 
50
EOF`
 
51
 
 
52
USAGE=`cat << EOF
 
53
Usage: tovid-test [OPTIONS] -in FILE
 
54
 
 
55
OPTIONS may be any of the following:
 
56
 
 
57
    -basic   Test VCD, SVCD, and DVD (Default)
 
58
    -dvd     Test DVD-compatible formats
 
59
    -all     Test all formats that tovid supports
 
60
    -ffmpeg  Test the ffmpeg backend
 
61
    -keep    Keep all output files
 
62
 
 
63
The input file may be any video file. Output
 
64
and logging go into a temporary directory
 
65
with a name like "tovid-test.1".
 
66
EOF`
 
67
 
 
68
KEEP_OUTPUT=false
 
69
DEBUG=false
 
70
ERRORS=0
 
71
LOG_FILE="tovid-test.log"
 
72
DEFAULT_OUTFILE="outfile.default"
 
73
TEST_FORMATS="vcd svcd dvd"
 
74
TEST_FFMPEG=false
 
75
 
 
76
get_args()
 
77
{
 
78
    while test $# -gt 0; do
 
79
        case "$1" in
 
80
            "-in" )
 
81
                # Input file to test
 
82
                shift
 
83
                INFILE="$1"
 
84
                ;;
 
85
            "-debug" )
 
86
                # Run tovid in -debug mode and print all output
 
87
                DEBUG=:
 
88
                ;;
 
89
            "-keep" )
 
90
                # Keep all output files, giving them unique names
 
91
                KEEP_OUTPUT=:
 
92
                ;;
 
93
            "-all" )
 
94
                # Test all formats
 
95
                TEST_FORMATS="dvd half-dvd svcd dvd-vcd vcd kvcd kdvd bdvd"
 
96
                ;;
 
97
            "-basic" )
 
98
                # Test three basic formats
 
99
                TEST_FORMATS="vcd svcd dvd"
 
100
                ;;
 
101
            "-dvd" )
 
102
                # Test the DVD-compatible formats
 
103
                TEST_FORMATS="dvd half-dvd dvd-vcd kdvd bdvd"
 
104
                ;;
 
105
            "-ffmpeg" )
 
106
                # Test the ffmpeg backend
 
107
                TEST_FFMPEG=:
 
108
                ;;
 
109
            "-cd" )
 
110
                # Test the CD-compatible formats
 
111
                TEST_FORMATS="vcd svcd"
 
112
                ;;
 
113
            * )
 
114
                usage_error "Unrecognized command-line option: '$1'"
 
115
                ;;
 
116
        esac
 
117
        shift
 
118
    done
 
119
}
 
120
 
 
121
# ******************************************************************************
 
122
# Y-echo: echo to two places at once (stdout and logfile)
 
123
# Output is preceded by the script name that produced it
 
124
# Args: $@ == any text string
 
125
# If no args are given, echo a separator bar
 
126
# Why echo when you can yecho?
 
127
# ******************************************************************************
 
128
yecho()
 
129
{
 
130
    if test $# -eq 0; then
 
131
        printf "\n%s\n\n" "$SEPARATOR"
 
132
        # If logfile exists, copy output to it (with pretty formatting)
 
133
        test -e "$LOG_FILE" && \
 
134
            printf "%s\n%s %s\n%s" "$ME" "$ME" "$SEPARATOR" "$ME" >> "$LOG_FILE"
 
135
    else
 
136
        echo "$@"
 
137
        test -e "$LOG_FILE" && \
 
138
            printf "%s %s" "$ME" "$@" >> "$LOG_FILE"
 
139
    fi
 
140
}
 
141
 
 
142
# ******************************************************************************
 
143
# Print usage notes and optional error message, then exit.
 
144
# Args: $@ == text string containing error message
 
145
# ******************************************************************************
 
146
usage_error()
 
147
{
 
148
    echo $"$USAGE"
 
149
    echo "$SEPARATOR"
 
150
    echo $@
 
151
    exit 1
 
152
}
 
153
 
 
154
# ******************************************************************************
 
155
# Test the tovid script with the given options and infile
 
156
# Args: $@ = all options (including -in) to test
 
157
#   -out filename will be ignored if provided
 
158
# ******************************************************************************
 
159
test_tovid()
 
160
{
 
161
    # If we're keeping every output file, generate a unique name
 
162
    if $KEEP_OUTPUT; then
 
163
        OUTFILE_UNIQUE=`echo $@ | sed 's/ //g'`
 
164
        OUTFILE="$OUTFILE_UNIQUE"
 
165
    else
 
166
        OUTFILE="$DEFAULT_OUTFILE"
 
167
        rm -f "$OUTFILE"
 
168
    fi
 
169
    CMD="tovid $@ -overwrite -out $OUTFILE"
 
170
    $TEST_FFMPEG && CMD="$CMD -ffmpeg"
 
171
    yecho $CMD
 
172
    if $DEBUG; then
 
173
        eval "$CMD" | tee -a "$LOG_FILE"
 
174
    else
 
175
        eval "$CMD" >> "$LOG_FILE"
 
176
    fi
 
177
 
 
178
    if test -e "$OUTFILE.mpg"; then
 
179
        # Report success
 
180
        echo "--------"
 
181
        echo "Success!"
 
182
        echo "$ME Detected a successful encoding" >> $LOG_FILE
 
183
        echo $SEPARATOR
 
184
        # TODO: Verify that output specs match the target format
 
185
        idvid "$OUTFILE" >> "$LOG_FILE"
 
186
    else
 
187
        # Count and log error
 
188
        ERRORS=`expr $ERRORS \+ 1`
 
189
        echo "$ME Detected an encoding failure" >> $LOG_FILE
 
190
        # Report failure
 
191
        echo "----------------"
 
192
        echo "*** Failure! ***"
 
193
        echo "Please see $LOG_FILE for error messages."
 
194
        # Report error
 
195
        echo $SEPARATOR
 
196
    fi
 
197
}
 
198
 
 
199
# ******************************************************************************
 
200
# Execution begins here
 
201
# ******************************************************************************
 
202
INFILE=""
 
203
get_args "$@"
 
204
if test -z "$INFILE"; then
 
205
    usage_error "Please provide the name of a video file to use as input."
 
206
fi
 
207
 
 
208
# Remove any existing log file
 
209
test -f "$LOG_FILE" && rm -fv "$LOG_FILE"
 
210
 
 
211
# Test each format in the list
 
212
for FMT in `echo $TEST_FORMATS`
 
213
do
 
214
    echo "Encoding to $FMT format"
 
215
    test_tovid "-$FMT -in $INFILE"
 
216
done
 
217
 
 
218
echo "There were $ERRORS errors. Please see $LOG_FILE for a complete report."
 
219
echo "Done. Thanks for using tovid-test."
 
220
 
 
221
exit 0