-- Inicio divx2vcd --
#!/bin/bash
# Este script pasa un Divx a VCD. Para los archivos temporales se
# necesita al menos 4.5 Gigas (m1v y mpa, los .mpg y los .bin)
DIR=`pwd`
TEMPFOLDER=/tmp/divx2vcd-$RANDOM
TEMP_TEMPLATE=/tmp/tcmplex-template-$RANDOM
# CDSIZE Values. VCDs are write in Mode 2, so the filesizes are the
# the following:
#* * * 74 Min/650Mb ---> CDSIZE=735
#* * * 80 Min/700Mb ---> CDSIZE=795
CDSIZE=795
#VIDEORATE=1150
AUDIORATE=224
if [ $# -eq 0 ]; then
* * * * echo "Usage:"
* * * * echo "* * * * divx2vcd <divxfile>"
* * * * exit 1
fi
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
* * * * FILE="$DIR/$1"
fi
mkdir $TEMPFOLDER
cd $TEMPFOLDER
tcprobe -i "$FILE" > $TEMPFOLDER/info
WIDTH=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
* perl -e ' $line=<stdin> ; $line =~ /width=(\d+)/* ;* print $1' `
HEIGHT=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
* perl -e ' $line=<stdin> ; $line =~ /height=(\d+)/* ;* print $1' `
FPS=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
* perl -e ' $line=<stdin> ; $line =~ /V: (.+?) fps/* ;* print $1' `
FPS_1=`echo "scale=1 ; $FPS/1"| bc -l`
FRAMES=`grep '\[avilib\] V:' $TEMPFOLDER/info | \
* perl -e ' $line=<stdin> ; $line =~ /frames=(\d+)/* ;* print $1' `
SEGUNDOS_TOTAL=`echo "scale=0 ; ($FRAMES / $FPS)"| bc -l`
HORAS=`echo "scale=0 ; ($SEGUNDOS_TOTAL / 3600)"| bc -l`
MINUTOS=`echo "scale=0 ; (($SEGUNDOS_TOTAL - 3600 * $HORAS)/60)"| \
* bc -l`
SEGUNDOS=`echo "scale=0 ; ($SEGUNDOS_TOTAL % 60)"| bc -l`
* * * *
echo "*************** FILE INFO ***************"
echo "Frame Size: ${WIDTH}x${HEIGHT}* -* FPS: $FPS"
echo "Length: $FRAMES* -* Seconds: $SEGUNDOS_TOTAL"
echo "$HORAS hours, $MINUTOS minutes, $SEGUNDOS seconds"
if [ $FPS_1 == "29.9" -o $FPS_1 == "30" -o* $FPS_1 == "23.9" ]; then
* * * * WIDTH_OUT=352
* * * * HEIGHT_OUT=240
else
* * * * WIDTH_OUT=352
* * * * HEIGHT_OUT=288
fi
echo "Video Output: ${WIDTH_OUT}x${HEIGHT_OUT}"
# Ahora calculamos los valores pa los bordes.
ANCHO_1_1_OUT=`echo "($HEIGHT_OUT * 4/3)"| bc -l`
ALTO_OUT=`echo "$HEIGHT / ($WIDTH / $ANCHO_1_1_OUT)" | bc -l`
# Redondeamos
ALTO_OUT=`echo "scale=0 ; $ALTO_OUT/1"| bc -l`
# Nos aseguramos de que sea par
ALTO_OUT=`echo "scale=0 ; $ALTO_OUT+$ALTO_OUT%2" | bc -l`
BORDE=`echo "scale=0 ; ($HEIGHT_OUT-$ALTO_OUT)/2"| bc -l`
echo "alto sin bordes: $ALTO_OUT, con borde: $BORDE"
# Borramos Pelicula.m1v y Pelicula.mpa
rm -f Pelicula.m1v Pelicula.mpa
cd $TEMPFOLDER
echo "transcode -i \"$FILE\" -V -x mplayer -y mpeg2enc,mp2enc \
* -F 1 -Z ${WIDTH_OUT}x$ALTO_OUT -Y -$BORDE,0,-$BORDE,0 \
* --export_asr 2 -E 44100* -b $AUDIORATE -o $DIR/Pelicula"
transcode -i "$FILE" -V -x mplayer -y mpeg2enc,mp2enc \
* -F 1 -Z ${WIDTH_OUT}x$ALTO_OUT -Y -$BORDE,0,-$BORDE,0 \
* --export_asr 2 -E 44100* -b $AUDIORATE -o $DIR/Pelicula
rm $TEMPFOLDER/*
rmdir $TEMPFOLDER
cd $DIR
# Si no hay Pelicula.m1v y Pelicula.mpa salir
[ -f Pelicula.m1v -a -f Pelicula.mpa ] || exit 1
rm -f Pelicula*.mpg
#Ahora multiplexamos el .mpg
echo "maxFileSize = $CDSIZE" > $TEMP_TEMPLATE
tcmplex -i Pelicula.m1v -p Pelicula.mpa -o Pelicula.mpg \
* -m 1 -F $TEMP_TEMPLATE
rm $TEMP_TEMPLATE
# Y creamos las imagenes...
for i in `ls Pelicula*mpg` ; do
* * * * vcdimager -t vcd2 -c $i.cue -b $i.bin $i
done
-- Final divx2vcd --