6
# Part of the tovid suite
7
# =======================
8
# Produce a short fast-forward-style preview of a video file.
10
# Project homepage: http://www.tovid.org
13
# Copyright (C) 2005 tovid.org <http://www.tovid.org>
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
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.
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:
30
# http://www.gnu.org/licenses/gpl.txt
32
# Author: Rick Measham aka Woosta: rick@measham.id.au
35
Usage: previd [OPTIONS] -in {input file} -out {output file}
37
OPTIONS may be any of the following:
39
-v, -version Prints previd version number only
41
-y NUM Sets width and height. Use multiples of 16
42
-sstep NUM Skip NUM seconds between frames
43
-fps NUM Show each frame NUM times.
47
SEPARATOR="========================================================="
59
TMP_DIR=$(tempdir previd)
61
# Make temp dir absolute
62
TMP_DIR="${CWD}/${TMP_DIR}"
63
LOG_FILE="${TMP_DIR}/previd.log"
65
# ******************************************************************************
66
# Print usage notes and optional error message, then exit.
67
# Args: $@ == text string containing error message
68
# ******************************************************************************
71
printf "%s\n" "$USAGE"
72
printf "%s\n" "$SEPARATOR"
78
# Step 0: Get the parameters
79
while test $# -gt 0; do
100
if test $(expr $WIDTH % 16) -ne 0; then
101
echo "-x must be a multiple of 16"
110
if test $(expr $HEIGHT % 16) -ne 0; then
111
echo "-y must be a multiple of 16"
131
echo "Unrecognised command-line option $1"
138
# Make sure infile and outfile were provided
139
if test -z "$INFILE" || test -z "$OUTFILE"; then
140
usage_error "Please provide input and output filenames using -in and -out options."
143
if test -e "$INFILE"; then :;
145
echo "Cannot open the input file $INFILE for reading."
150
printf "%s\n" "$SEPARATOR"
151
echo "Generating JPEGs from mplayer with the following command:"
152
GEN_JPEG_CMD="mplayer -nosound -noautosub -vo jpeg:outdir=$TMP_DIR -sstep $STEP -vf scale=$WIDTH:$HEIGHT $INFILE"
154
#eval "$GEN_JPEG_CMD >> $LOG_FILE 2>&1"
157
printf "%s\n" "$SEPARATOR"
158
echo "Creating symbolic links to get the multiple frames..."
159
FRAMECOUNT=$(ls -l $TMP_DIR/*.jpg|wc -l)
161
for i in $(seq 1 $FRAMECOUNT); do
162
FI=$(printf "%08d" $i)
163
for j in $(seq 1 $FRAMES_PER_STEP); do
165
FND=$(printf "%08d" $FN)
166
$(ln -s ${TMP_DIR}/$FI.jpg ${TMP_DIR}/out.$FND.jpg)
171
echo "Step 3: Turn the symbolic links into an m2v"
172
TO_M2V_CMD="jpeg2yuv -v 0 -b 1 -f 24 -j $TMP_DIR/out.%08d.jpg -I p | mpeg2enc -a 1 -n p -f 8 -o $TMP_DIR/$OUTFILE.m2v"
176
echo "Step 4: Turn the m2v into an mpg"
177
mplex -o $OUTFILE.mpg $TMP_DIR/$OUTFILE.m2v
179
echo "Step 5: Clean up the temporary files"
182
echo "$INFILE has been shortened by stepping $STEP and resized to $WIDTH x $HEIGHT."
183
echo "Each resulting frame is now $FRAMES_PER_STEP frames of the final file"
184
echo "The final file has been saved to $OUTFILE.mpg"